the name of the related model
the field(s) that should be used to reference the related model
a one-to-many relationship definition
const schema = a.schema({
Member: a.model({
name: a.string().required(),
// 1. Create a reference field
teamId: a.id(),
// 2. Create a belongsTo relationship with the reference field
team: a.belongsTo('Team', 'teamId'),
})
.authorization(allow => [allow.publicApiKey()]),
Team: a.model({
mantra: a.string().required(),
// 3. Create a hasMany relationship with the reference field
// from the `Member`s model.
members: a.hasMany('Member', 'teamId'),
})
.authorization(allow => [allow.publicApiKey()]),
});
Create a one-directional one-to-many relationship between two models using the
hasMany("MODEL_NAME", "REFERENCE_FIELD(s)")
method.