Files
main.tsmain
What you'll learn
- Declare a one-to-many relation and its inverse many-to-one, and say which side holds the foreign key
- Explain why a relation property typed with the bare class can fail at load time under ES modules, and type it with Relation<>
- Load a relation on request with relations: { ... }, and set one by assigning the entity and saving
Press Run tests to start the app. Its log appears here.Graded endpoints
An owner row
A cat with no owner yet
A second cat
The relation is loaded and empty, so owner is null, not absent
The owner was assigned and saved; the foreign key lives on the cat row
findOneBy on the owner returned null
findOne loads the relation
The inverse side, loaded from the owner
One owned cat, one not