qwertyuiop
qwertyuiop

Reputation: 3

One to Many Associate objects with sequelize

If I have two objects Project and Task associated with one-to-many relation

 Project.hasMany(Task)     
 var Pro1 = Project.build({...}).save();

Now when I set a new task to one person after saving it

var task = Task.build({ ... }).save().success(function(t1)){
     project.setTasks([t1]).success(function() {
            // saved!
      })
})

the first task works fine, but with the second task I get the following error

TypeError: Cannot read property 'omitNull' of undefined
    at  {myhome}/node_modules/sequelize/lib/associations/has-many-single-linked.js:21:65

How can add more tasks to the previous, and be able to get them later with

Pro1.getTASKs

Upvotes: 0

Views: 2703

Answers (2)

sdepold
sdepold

Reputation: 6231

this issue is fixed in 1.5.0-beta :) go for it!

Upvotes: 0

sdepold
sdepold

Reputation: 6231

sadly your code is kinda strange, as you are using different variable names in those three code examples. However, this is how you would do it: https://gist.github.com/3040391

In order to add other tasks you can do project.addTask(myNewTask)

Upvotes: 1

Related Questions