Define associations in fixtures
masterTo handle relationships, ensure that associated objects are described in the fixture file before the objects that reference them. You can link entities using IDs or property-value maps.
One-to-Many (belongsTo / hasMany)
Using ID:
[
{ "model": "Owner", "data": { "id": 11, "name": "John" } },
{ "model": "Car", "data": { "owner": 11 } }
]Using a property-value map (where clause):
[
{ "model": "Owner", "data": { "name": "John" } },
{ "model": "Car", "data": { "owner": { "name": "John" } } }
]Many-to-Many (belongsToMany)
Use the association's as name or the through table name. Provide an array of IDs or an array of property-value maps.
Using IDs:
[
{ "model": "Person", "data": { "id": 122, "name": "Jack" } },
{ "model": "Project", "data": { "people": [122] } }
]Using property-value maps:
[
{ "model": "Person", "data": { "name": "Jack" } },
{ "model": "Project", "data": { "people": [{ "name": "Jack" }] } }
]Custom Through Model attributes:
If using a custom through model, use the _through key to set additional attributes on the join table.
[
{ "model": "Actor", "data": { "name": "Arnie", "movies": [{ "name": "Terminator", "_through": { "character": "T-80" } }] } }
]