我想要的是:根据数据库的id(uuid)从数据库中获取一条记录,并检索下一条和上一条记录
关联: posts N:M categories, posts 1:N comments, posts N:1 users, posts N:M tags, posts 1:N post_views
当前解决方案:
const post = await PostModel.findByPk(id, {
include: [
{ model: CategoryModel, attributes: ['title'] },
{ model: TagModel },
{ model: CommentModel, include: { model: UserModel } },
{ model: PostViewModel },
{ model: UserModel, attributes: ['fullname', 'id', 'avatar'] }
]
});
const nextPost = await PostModel.findOne({
where: { createdAt: {
[Op.gt]: post.createdAt
}}
const prevPost = await PostModel.findOne({
where: { createdAt: {
[Op.lt]: post.createdAt
}}
});
但我认为这不是有效和好的。
暂无答案!
目前还没有任何答案,快来回答吧!