我有sequelize的问题。这就是我想要做的事情:
return pointsTransaction.findAndCountAll({
where:{
user_id: userId
},
limit: opts.limit,
offset: opts.offset,
include:[{
model:sequelize.models.pointsPendingtransaction
}]
});
生成的查询如下所示:
SELECT "pointsTransaction".*,
"pointsPendingtransactions"."transaction_ptr_id" AS "pointsPendingtransactions.transactionPtrId",
"pointsPendingtransactions"."is_active" AS "pointsPendingtransactions.isActive",
"pointsPendingtransactions"."transaction_id" AS "pointsPendingtransactions.transaction_id"
FROM (
SELECT "pointsTransaction"."id",
"pointsTransaction"."date_time" AS "dateTime",
"pointsTransaction"."details",
"pointsTransaction"."points",
"pointsTransaction"."user_id"
FROM "points_transaction" AS "pointsTransaction"
WHERE "pointsTransaction"."user_id" = 10002 LIMIT 1000
) AS "pointsTransaction"
LEFT OUTER JOIN "points_pendingtransaction" AS "pointsPendingtransactions"
ON "pointsTransaction"."id" = "pointsPendingtransactions"."transaction_id"
所以在SQL中我只需要在查询结束时添加该行以使其正常工作:WHERE "pointsPendingtransactions"."transaction_id" IS null
所以我的问题是,我怎么能用续集来做到这一点?我尝试了许多不同的方法,但没有人工作......
答案 0 :(得分:2)
尝试做下一步
where: {
transaction_id: {
$eq: null
}
}
生成IS NULL
return pointsTransaction.findAndCountAll({
where:{
user_id: userId
},
limit: opts.limit,
offset: opts.offset,
include:[{
model:sequelize.models.pointsPendingtransaction,
where: {
transaction_id: {
$eq: null
}
}
}]
});
答案 1 :(得分:0)
如果您正在使用Sequelize.Op中的Sequelize符号运算符,则...
def __str__(self):
return u'%s' % (self.shipper_number)