alexis
alexis

Reputation: 31

Node.js Sequelize findAll() column of included table model

I'm trying to search for the following condition in a merged table between two tables.

It should collect and return records that has the buyer 'alex' or seller 'alex'. The buyer exists in Chat table and seller exists in Market table which I have included as shown below. However, I am unable to get it to work. Any ideas are welcome.

Chat.findAll({
        where: {
           buyer: 'alex',
               seller: 'alex'

          },
        include: [{
          model: Market,
          required: true
         }]
      })

Upvotes: 0

Views: 559

Answers (1)

AbhinavD
AbhinavD

Reputation: 7282

The seller has to be inside Market

Chat.findAll({
        where: {
           buyer: 'alex',
          },
        include: [{
          model: Market,
          required: true,
          where: {
            seller: 'alex'
          }
        }]
      })

Upvotes: 1

Related Questions