Skip to content

Setting array of association #97

Description

@freemanrnd

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions