gpt4 book ai didi

javascript - Sequelize 包含嵌套列 : Unknown column in 'where clause'

转载 作者:行者123 更新时间:2023-12-04 11:14:18 26 4
gpt4 key购买 nike

我正在尝试使用 Sequelize ORM 的功能,该功能允许从包含的模型中引用嵌套列(参见 Sequelize Docs: Complex where clauses at the top-level)。在文档中指出,我可以使用 $nested.column$句法。
以下是我试图做的事情:

let where = { memberId };
if (req.query.search) {
const like = { [Op.like]: `%${req.query.search}%` };
where = {
...where,
[Op.or]: [
{ '$bookItem.serial$': like },
{ '$bookItem.book.name$': like },
{ '$bookItem.book.ISBNCode$': like },
],
};
}

const options = {
where,
include: [
{
model: models.BookItem,
as: 'bookItem',
required: false,
include: [
{
model: models.Book,
as: 'book',
attributes,
required: false,
},
],
},
],
});

const transactions = await models.Borrow.findAll(options);
但是,对于上面的代码,我收到以下错误: "Unknown column 'bookItem.serial' in 'where clause'"我错过了什么?
完整数据库架构: https://dbdiagram.io/d/5e08b6aaedf08a25543f79cb

最佳答案

bookitem一张 table ?还是数据库?bookItem.serial任一代表 db.tbltbl.columnbookItem.book.name只能代表db.tbl.column由于bookItem好像是数据库名,然后serial必须是表名。此时,“tablename LIKE ...”是一个语法错误。

关于javascript - Sequelize 包含嵌套列 : Unknown column in 'where clause' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65982811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com