Skip to content
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

Derive "diesel::Identifiable" if struct has a primary-key #135

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

hasezoey
Copy link
Collaborator

This PR adds derive diesel::Identifiable to all Read-structs which have a primary key.

fixes #133

Note: personally i thought the Identifiable is only necessary for Associations or if you want to use the struct directly in a update (see doc quote)

This must be implemented to use associations.
Additionally, implementing this trait allows you to pass your struct to update (update(&your_struct) is equivalent to update(YourStruct::table().find(&your_struct.primary_key())

source


@longsleep does this properly fix you case? also could you explain why it would be necessary aside from Associations or is the second "helper"(the update(&struct)) the reason?

@longsleep
Copy link
Collaborator

@longsleep does this properly fix you case? also could you explain why it would be necessary aside from Associations or is the second "helper"(the update(&struct)) the reason?

Users of the generated structs might need the Identifiable trait in their own code (like to get access to the id function or for other purposes).

@longsleep longsleep self-requested a review August 21, 2024 14:55
Copy link
Collaborator

@longsleep longsleep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to finally get this as part of a release.

@hasezoey hasezoey merged commit 11b65ef into Wulf:main Aug 21, 2024
6 checks passed
@hasezoey hasezoey deleted the identifiable branch August 21, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The diesel::Identifiable trait is not derived for the table a foreign key refers to
2 participants