I would like to set association to several entities and persist the associations.
For example:
var Person = db.define('person', { name: String })
var Pet = db.define('pet', { name: String })
Person.hasMany('pets', Pet);
var jake = new Person({ name: "Jake" });
jake.save(function(err) {
Pet.create([{name: "Smokey"},{name: "Pluto"},{name: "Bubba"}],function(err, pets){
jake.setPets(pets, function(err){
jake.save(function(err){if(err){throw err;}console.log('Yep!');});
});
});
});
I run it and see:
$ node app.js
Yep!
mysql> SELECT * FROM person_pets;
Empty set (0.00 sec)
It works as I expect If I use following code:
jake.setPets(pets[0], pets[1], pets[2], function(err){...});
Is there any method to set several associations passing them within one object?
Thanks.
I would like to set association to several entities and persist the associations.
For example:
I run it and see:
It works as I expect If I use following code:
Is there any method to set several associations passing them within one object?
Thanks.