此原始查询的等效sequelize查询是什么?

时间:2016-01-22 04:47:07

标签: javascript mysql node.js express sequelize.js

SELECT offers.id FROM提供WHERE offers.user_id!=' 2'和offers.id不在(从notifications_offers.user_id =' 2')中选择notifications_offers.offer_id from informed_offers;

1 个答案:

答案 0 :(得分:0)

如果您已关联OffersNotifiedOffers模型,并且它不是多对多关联,则可以执行以下操作:

Offers.findAll({
    attributes: ['id'],
    where: {
        user_id: {
            not: 2
        }
    },
    include: {
        model: NotifiedOffers,
        where: {
            user_id: {
                not: 2
            }
        },
        required: true
    }
});