繁体   English   中英

Sequelize多对多关系:如何根据AND条件获得结果?

[英]Sequelize many-to-many relationship: How to get result based on AND condition?

我希望有人能帮助我解决这个问题,或者如果我弄错了,可以提供替代方案。 我有两个表之间的多对多关系。

为简单起见,我们假设有EventsUsersEventUsers ,其中EventUsers表具有eventIduserId

如何根据用户应明确为abc@test.comcde@test.com的条件实现Events表中的所有事件。

我尝试做这样的事情,但无济于事。

await Event.findAll({
    include: [
      {
        model: User,
        attributes: ['email'],
        through: {
          model: EventUsers,
          attributes: [],
        },
        where: {
          [Op.and]: [{ email: 'abc@test.com' }, { email: 'cde@test.com' }],
        },
      },
    ],
  });
Event table
------------
id | title
------------
1  | lorem
2  | ipsum


User table
------------
id | email
------------
1  | abc@test.com
2  | cde@test.com
3  | efg@test.com


EventUsers table
------------
eventId| userId
------------
1  | 1
1  | 2
2  | 1
2  | 2
2  | 3

这必须给我一个 ID 为 1 的事件,其中电子邮件是abc@test.comcde@test.com

在 where 条件下尝试“Op.or”而不是“Op.and”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM