我想从Table book和Table章节中获取数据,并希望将Table章节中的一行合并到Table book中。
我想将最大章节续写数的行添加到表中
nodejs 10.5 续订4.8.0
let result = await model.shelf.findAll({
where: {
userId: id
},
attributes: ['id', 'type', 'lastChapter', 'createTime'],
include: [
{
model: model.book,
attributes: {
include: ['bookName', 'poster'],
exclude: ['updateTime', 'createTime', 'site', 'source', 'summary']
},
as: 'book',
include: [
{
model: model.chapter,
attributes: {
include: ['id', 'chapterName', 'createTime'],
exclude: ['updateTime', 'site', 'source', 'words', 'content', 'bookId']
},
where: db.where(db.col('chapter.seq'), db.fn('max', db.col('chapter.seq'))), // '$chapter.seq$': db.fn('max', db.col('chapter.seq'))
as: 'chapter',
// order: [
// [db.fn('max', db.col('chapter.seq')), 'DESC']
// ],
},
{
model: model.author,
attributes: {
include: ['name'],
exclude: ['createTime', 'updateTime', 'introduce', 'level', 'avatar'],
},
as: 'author'
}
]
},
],
order: ['updateTime'],
group: ['id']
});
[
{
..attributes,
book: {
chapter: {
...(max seq of Chaper)
},
author: {
...authorAttributes
}
}
},
...
]
但是发生了错误
err name: SequelizeDatabaseError
err message: missing FROM-clause entry for table "chapter"
err stack: SequelizeDatabaseError: missing FROM-clause entry for table "chapter"