-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert primary keys to serialize_as type #4168
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR. I think this is a reasonable change, although I have some concerns around backward compatibility here. Depending on what the other members of the contributor team decide we might or might not move forward with this change.
If we move forward we likely want to have a changelog entry for this.
.. | ||
} = &model.find_column(pk)?; | ||
if let Some(AttributeSpanWrapper { item: ty, .. }) = serialize_as.as_ref() { | ||
field_ty.push(quote!(#ty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that might be seen as breaking change, although one could also argue that this is a bug fix. Pinging @diesel-rs/contributors to get some more opinions on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm a recent Diesel reviewer, so don't give my opinion too much weight)
There are two changes here, right?
- One seems to me clearly a bugfix: for a composite primary key, we miss the
&'ident
/&self
for all but the first element, leading to potential nonsense. We should just fix that. - The other is less clear: we apply
serialize_as
when we didn't before. Clearly we "should" apply it, but could people be depending on this in some way? I don't have enough experience to know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, composite primary key already works (as shown in the tests), so this is not a fix. The &'ident
/ &self
part was repeated for every element already, as per quote!
's interpolation.
Here I changed field_ty
and field_name
to be Vec<TokenStream>
directly, so I can push what will be needed by the impl
directly.
10acd91
to
096ed84
Compare
096ed84
to
f17db14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we go with the current variant. I would like to see an Changelog entry for this before merging otherwise the code + test cases look ok.
119efdc
to
2c842cf
Compare
I've added a changelog entry and rebased the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update
I've got a newtype on oxydized_money::Currency to implement ToSql/FromSql/...
I recently added a table with a composite primary key which included a currency column, and I'm expecting to be able to use it the same way I used another id.
Everything seems fine, until I try to compile the following instruction:
Or as explained a few lines later:
I can fix that by implementing
Identifiable
andHasTable
manually, or by compiling against the provided patchIt works because my type is
Copy
, but at the same time this isn't uncommon for id types.When it's not copy, I get something like:
Plus some advice on implementing
Clone
, if it's not alreadyClone
.I could maybe find a way of ensuring the type is
Copy
if you think it's better that way, but if we go this way we might as well relax theAsChangeset
&Insertable
restriction onserialize_as
for the same reasons, so it would be a bigger change.Tell me what you think