ORM-25: Add relationship helpers to the schema builder #25
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#25
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, #24
Context
1-1, 1-n and n-m relations all come down to a foreign key column or a pivot table. The helpers generate the right shape. Column names are explicit; there is no singularisation magic (
categoriestocategory_idis not guessable).Tasks
t.foreign_key("user_id", "users")emitsuser_id INTEGER NOT NULL REFERENCES users(id). Options:.nullable(),.unique()(for 1-1) and.on_delete(Cascade | SetNull | Restrict). It also creates an index on the FK column unless.unique()is set.s.create_pivot("post_tags", ("posts", "post_id"), ("tags", "tag_id"))emits a composite PK, both FKsON DELETE CASCADE, and an index on the second column.Example
Generated SQL for the 1-n example and the pivot:
Acceptance criteria
PRAGMA table_infoandPRAGMA foreign_key_list).Model::schema()and a schema drift check #26