sequelize.js - Getting info from associated tables -


i have 2 tables:

---id---userid--- , ---id---productid---productname--- 

so, associated following code:

product.belongstomany(user, {through: 'resultingproducts', foreignkey: 'userid'}); user.belongstomany(product, {through: 'resultingproducts', foreignkey: 'productid'}); 

i've tried products "product" current user

        product.sync()         .then(() => {             product.findall({                 include: [user],                 through: {                     where: {                         userid: userid                 }         }) 

but code returns products users in db. me?

you should querying on user model rather products model. try changing code following find products 'related' 'this' user.

user.findall({   include: {     model: product, // product product model     through: {attributes: []} // remove rows join table in result   },   where: { userid: userid } // note, clause outside 'include' , 'through' }) 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -