我正在使用Sequelize將項目從MySQL移動到Postgres,並且有一件事情直接失敗了。這看起來是因爲「用戶」不在任何地方。Where子句在`OR`語句中使用包含關係
編輯:錯誤消息是'缺少表用戶的FROM-clause條目'。
代碼爲sequelize是:
List.model.findOne({
where: {
id: listId,
$or: [
{ open: true },
['Users.id = ?', [userId]], // <-- the line I think is breaking this.
],
},
include: [{
model: db.models.User
}],
});
我認爲這是由於User
不被包括在FROM
子句。但是,我不知道如何讓Sequelize做正確的事情。
通過Sequelize生成的查詢是:
SELECT "List"."id",
"List"."name",
"List"."image",
"List"."slug",
"List"."open",
"List"."password",
"List"."createdAt",
"List"."updatedAt",
"List"."OwnerId",
"Users"."id" AS "Users.id",
"Users"."firstName" AS "Users.firstName",
"Users"."lastName" AS "Users.lastName",
"Users"."email" AS "Users.email",
"Users"."password" AS "Users.password",
"Users"."image" AS "Users.image",
"Users"."facebookId" AS "Users.facebookId",
"Users"."googleId" AS "Users.googleId",
"Users"."createdAt" AS "Users.createdAt",
"Users"."updatedAt" AS "Users.updatedAt",
"Users.UserList"."createdAt" AS "Users.UserList.createdAt",
"Users.UserList"."updatedAt" AS "Users.UserList.updatedAt",
"Users.UserList"."ListId" AS "Users.UserList.ListId",
"Users.UserList"."UserId" AS "Users.UserList.UserId"
FROM "Lists" AS "List"
LEFT OUTER JOIN ("UserList" AS "Users.UserList"
INNER JOIN "Users" AS "Users" ON "Users"."id" = "Users.UserList"."UserId") ON "List"."id" = "Users.UserList"."ListId"
WHERE "List"."id" = 13
AND ("List"."open" = TRUE
OR (Users.id = 1234));
什麼是錯誤消息? –
缺少來自表用戶的FROM子句條目 – David