I\'m having troubles saving data in a \"many-to-many\" relationship.
Here are my models:
var CoursePeople = bookshelf.Model.extend({
tableName: \'c
What you want to do here is attach the ids to your relation, like this:
app.post('/users/', function(req,
console.log(req.body);
var courses_ids = req.body.courses_ids; //array of ids
delete req.body.courses_ids;
new User(req.body).save()
.then(function(user){
// this is important
return user.courses().attach(courses_ids);
}).catch(function(error){
console.log(error);
});
});
It is also stated in the official docs: http://bookshelfjs.org/#Model-attach