Relations — Techniques · NestJS

Give cats owners: a one-to-many and its many-to-one, typed with Relation<> so the two entity files can import each other under ES modules, loaded on request and set by assignment.

What you will learn

Read the theory for Relations

All Techniques lessons

All NestJS courses

loading types…

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