One to Many Associate objects with sequelize
-
18-06-2021 - |
Question
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
Solution
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)
OTHER TIPS
this issue is fixed in 1.5.0-beta :) go for it!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow