Skip to content

Does AsChangeset skip referenced fields and primary key? #4355

Closed Answered by weiznich
commonuserlol asked this question in Q&A
Discussion options

You must be logged in to vote

Diesel generally inserts/updates all fields to the provided values. So if you set something to 0 diesel will set the database field to zero. The only exception there are primary key fields for updates.
In addition to that both Insertsable and AsChangeset have special behaviour for optional fields. If such a field is None for an insert statement the database side default value is used. For updates the field is skipped.

The Identifiable derive is usefully for identifying a database entry, which requires a primary key value. For that by default the id field is used but you can specify one or more other fields via the #[diesel(primary_key())] attribute.

All of this is explained in depth in the

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@commonuserlol
Comment options

@weiznich
Comment options

@commonuserlol
Comment options

@commonuserlol
Comment options

Answer selected by commonuserlol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants