ORM-20: Implement BelongsTo #20
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#20
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: #18
Context
The inverse of
HasMany/HasOne: the model holding the foreign key looks up its parent (post.author()).associatesets the FK field without saving, so the child becomes dirty andsave()persists it, like Eloquent.Tasks
BelongsTo::<C, P>::new(fk: Column<C, i64>, get_fk: fn(&C) -> Option<i64>, set_fk: fn(&mut C, Option<i64>)), plus a const.nullable()marker..of(&child)returns a handle withfirst() -> Result<Option<P>>. A NULL FK returnsNonewithout querying.associate(&mut child, &parent) -> Result<()>sets the FK (the parent must be persisted, otherwiseError::NotPersisted).dissociate(&mut child)sets it to NULL and returns the newError::NotNullableunless the relation was marked.nullable().post.author().Example
Acceptance criteria
Noneand runs no query.associatemakes the child dirty on its FK column andsave()persists it.dissociateon a non-nullable relation returnsNotNullable.load_for) to avoid N+1 queries #23