Reputation: 1214
http://sailsjs.org/documentation/concepts/models-and-orm/associations/through-associations
AS per above link, I have created 3 models "User", "Pet" and "Pet_user", then I used below request to insert the record. But, it inserts user and pet table instead of pet_user table.
{
"name":"BB21",
"user_name":"BB21",
"email_personal" : "[email protected]",
"email_official" : "[email protected]",
"pets" : [
{
"pet" : 1,
"owner" : 1
}
]
}
//Controller
create: function(req, res) {
User.create(req.params.all()).exec(function(err, user) {
if (err)
return res.json(402, err);
if(user) {
res.json('200', {message: sails.config.messages.USERCREATION});
}
});
},
Upvotes: 0
Views: 44
Reputation: 98
Id has to be included while using through in model collection
{
"name":"BB21",
"user_name":"BB21",
"email_personal" : "[email protected]",
"email_official" : "[email protected]",
"pets" : [
{
"id" : 1
}
]
}
Upvotes: 1