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

萝らか妹 提交于 2019-12-25 02:21:35

问题


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
         }]
      })

回答1:


The seller has to be inside Market

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


来源:https://stackoverflow.com/questions/51000931/node-js-sequelize-findall-column-of-included-table-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!