Relations
Add a relationship between two entities, like an Invoice that belongs to a Customer, a Pet that belongs to an Owner, etc.
note
As of today, only the BelongsTo and thus its opposite hasMany are available.
ManyToMany relationships are coming soon.
BelongsTo relationship
Syntax
This is a standard HasMany / BelongsTo relationship between User and Cat entities.
Each User can have several Cat items. A Cat must have a User.
😃 User:
properties:
- name
😺 Cat:
properties:
- name
belongsTo:
- User
As for the properties, there is a short and a long syntax. The long syntax allows you pass params to it:
🐶 Dog:
properties:
- name
belongsTo:
- { name: Owner, entity: User, eager: true }
Relation params
You can pass arguments using the long syntax:
Option | Default | Type | Description |
---|---|---|---|
name | Entity name | string | The name of the relation |
entity | - | string | The class name of the entity that the relationship is with |
eager | false | boolean | Whether the relationship should be eager loaded. Otherwise, you need to explicitly request the relation in the client SDK or API |