Wulf / dsync

Generate rust structs & query functions from diesel schema files
Other
70 stars 13 forks source link

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

Closed hasezoey closed 1 month ago

hasezoey commented 8 months ago

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 commented 8 months ago

@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).