我有三个模型Books,Author和Editor的关系如下
Books.hasMany(Author);
Author.belongsTo(Editor);即使作者不匹配,我也会得到所有的书。下面是我到目前为止尝试过的
Attributes.push('Id','Name')
Books.findAll({
include: [
{model: Author, where:{Author:'XYZ'} ,attributes:, separate: true}
, {model: Editor}
]
, where:{ book_publication:'ABC' }
});我的产量越来越低了。但由于没有作者XYZ,因此图书Id=2预计不会印刷。
{
"data": {
"Books": [
{
"Id": 1,
"Path": "/home/ubuntu/book1.pdf",
"Name":"book1.pdf"
"DateProposed": "2021-04-30 09:44:38",
"book_publication":"ABC"
"Author": [
{
"Id": 1,
"Author":"XYZ"
"Size": 10,
}
],
"Editor":{
"Name":"PQRS"
}
},
{
"Id": 2,
"Path": "/home/ubuntu/book2.pdf",
"DateProposed": "2021-04-07 12:22:36",
"book_publication":"ABC"
"Author": [],
"Editor": {
"Name": "PQRS"
}
}
]
}
}发布于 2021-05-04 04:39:05
也许您应该在Editor模型中添加required标志。
{model: Editor, required: true },https://stackoverflow.com/questions/67370541
复制相似问题