1
votes

If I have a JSON object as follows

{
 name: "John Smith",
 tags: [1, 2, 3]
}

Each number in the tags array above is a foreign key associated with a Tag record.

What's the most efficient way of creating this record using sequelize?

1

1 Answers

0
votes

Guessing your relations are like

Person.hasMany(Tag);
Tag.hasMany(Person);

You could create a Person and later on find those tasks and assign them to him

Person.create(obj)
   .success(function (person) {
      Tag.findAll({where: { id: obj.tags }})
         .success(function (tags) {
            person.setTags(tags);
         });
   });