此原始查询的等效续集查询是什么?
what is the equivalent sequelize query for this raw query?
SELECT offers.id FROM offers WHERE offers.user_id != '2' and offers.id not in (select notified_offers.offer_id from notified_offers 其中 notified_offers.user_id = '2');
如果您关联了 Offers
和 NotifiedOffers
模型,并且它不是 many-to-many 关联,您可以这样做:
Offers.findAll({
attributes: ['id'],
where: {
user_id: {
not: 2
}
},
include: {
model: NotifiedOffers,
where: {
user_id: {
not: 2
}
},
required: true
}
});
SELECT offers.id FROM offers WHERE offers.user_id != '2' and offers.id not in (select notified_offers.offer_id from notified_offers 其中 notified_offers.user_id = '2');
如果您关联了 Offers
和 NotifiedOffers
模型,并且它不是 many-to-many 关联,您可以这样做:
Offers.findAll({
attributes: ['id'],
where: {
user_id: {
not: 2
}
},
include: {
model: NotifiedOffers,
where: {
user_id: {
not: 2
}
},
required: true
}
});