Reputation: 479
I've two models, A and B which extends user buildt-in model. They both have a relation "has many" with each other using a through model A_B. I want to add an instance of B related with an existing A instance. I've try to post the new B instance with a field As ("As" is the relation name) setted with an array containing the A instance
var b = {"property1":"asdf","property2":"asdf","As":a};
$http.post(serverURL+"/api/bs",b);
The b instance is created, but there is no relation created. I must to create the A_B instance by hand (or in "after save" hook)?
PD: I'm using angularjs and it's $http service to make API calls.
Upvotes: 0
Views: 58
Reputation: 1205
Check this out: HasManyThrough relation
The advantage of using this approach: new url endpoints are created along with common CRUD operation i.e. New rest endpoint has its own specific tasks and therefore, its usage is easy to understand and is more maintainable. These rest endpoints will create relations in the database as the CRUD operations happen. You can get the generated url using loopback api on browser.
Upvotes: 1