node.js - Sequelize chaining methods -


i resql changing sequelize's function of:

students.find({where: {id: 34235}}).success(function(student) {     student.getcourses().success(function(courses) {         console.log(courses);     }); }); 

to:

students.one({id: 34235}).courses().then(function(courses) {     console.log(courses); }); 

i wondering if there way sequelize?

for example:

models.user.find(1).getproducts() 

i keep getting error:

typeerror: object [object promise] has no method 'getproducts' 

thanks!

this not possible in sequelize - node async nature, , have way user found before can call getproducts.

however can use includes:

user.find({    where: {     id: x   },    include: [course] }).then(function (user) {; 

this left join user course , able access user.course (or user.course, depending on name of course model)


Popular posts from this blog