Reputation: 479
I've a model called "jornal" with has two belongsTo relation, with models "obra" and "operario". Both of them have a hasMany relation with "jornal" model.
How can I create an instance of "jornal" model related with an "obra" instance and with an "operario" instance?
I've try chain a post to operario/id/jornal POST sending jornal object (without id, because it's a new instance), and then a POST to obra. If I send without id, it creates a new jornal instance, and if I send the whole object returned from previous POST, it says duplicate id.
Thanks
Upvotes: 2
Views: 847
Reputation: 814
POST /jornals
with data object
{
"obraId": 1,
"operarioId": 1
}
Set ids to whichever 'obra' and 'operario' objects you wish to relate to.
Upvotes: 1
Reputation: 625
I'm just started with loopback, but I think HasMany polymorphic relation will help you.
https://docs.strongloop.com/display/public/LB/Polymorphic+relations
Upvotes: 0