ORM-03: Make the primary key explicit on Model #3
Labels
No labels
area:core
area:database
area:migrations
area:model
area:relations
area:schema
area:tests
breaking-change
size:M
size:S
tracking
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
NoctisWolfshadow/tessera-orm#3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Depends on: #1
Context
Model::insertsilently treatsCOLUMNS[0]as the autoincrement key andCOLUMNS[1..]as the insertable columns. Relationships,find,updateandsaveall need to know the primary key explicitly, and it should not have to be the first column.Tasks
const PRIMARY_KEY: &'static str = "id";,fn id(&self) -> i64andfn set_id(&mut self, id: i64)toModel.COLUMNSminusPRIMARY_KEY(no more[1..]) in apub(crate) fn insert_sql() -> String.insert_values()returns the non-PK values inCOLUMNSorder.debug_assert_eq!its length againstCOLUMNS.len() - 1when inserting.Userfixture intests/common.Example
insert_sqlis crate-private, so the test lives next to it insrc/model.rs:Acceptance criteria
Notes
#4 adds the
ModelStatehooks to the same fixtures, so theLegacytest model needs them too once that lands.ModelState#4