Is it possible to filter a query by the attributes in the association table with sequelize?

前端 未结 2 480
渐次进展
渐次进展 2020-12-24 08:24

I am trying to filter my query by the attributes of the joining table

I have 2 tables Cities and Categories which I am associating through a third table CityCategory

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 08:35

    When querying the through table, you should use through.where

    include: [{
      model: Category,
      through: { where: {year: 2015}},
      attributes: ['id']
    }]
    

    You might want to add required: true to turn the include to an inner join

提交回复
热议问题