【发布时间】:2016-04-28 14:39:08
【问题描述】:
SELECT offer.id FROM offer WHERE offer.user_id != '2' and offer.id not in(从 notify_offers where notify_offers.user_id = '2' 中选择 notify_offers.offer_id);
【问题讨论】:
标签: javascript mysql node.js express sequelize.js
SELECT offer.id FROM offer WHERE offer.user_id != '2' and offer.id not in(从 notify_offers where notify_offers.user_id = '2' 中选择 notify_offers.offer_id);
【问题讨论】:
标签: javascript mysql node.js express sequelize.js
如果您已关联 Offers 和 NotifiedOffers 模型,并且它不是多对多关联,您可以这样做:
Offers.findAll({
attributes: ['id'],
where: {
user_id: {
not: 2
}
},
include: {
model: NotifiedOffers,
where: {
user_id: {
not: 2
}
},
required: true
}
});
【讨论】:
NotifiedOffers.belongsTo(Offers,{foreignKey:'offer_id'}) 对你有用,但你可以在这里获得更多信息:docs.sequelizejs.com/en/latest/docs/associations