sequelize node js query many to many relationship using where

Viewed 24

I have this relationship

User -> Cartlists <- Product

I am trying to show the products I have in my cartlists by querying it like this using the where function

router.get('/cart', ensureAuthenticated, async function (req, res) {
    let cartlists = await Cartlist.findAll()
    Product.findAll({
        include: User,
        where: { productId: cartlists.productProductId },
        raw: true
    })
        .then((cartlists) => {
            res.render('checkout/cart', { cartlists });
        })
        .catch(err => 
            console.log(err));
})

However, when I debugged it, it shows me that cartlists.productProductId is undefined even though there is a value in mySQL. I also get an error message saying

'WHERE parameter "productId" has invalid "undefined" value'

Does anyone know why it gives me an undefined value even though there are indeed values in MySQL table and how I might be able to fix this? Or how can I query just the products I have added to my cartlists table?

0 Answers
Related