问题描述
我需要为内部联接(必需:true)和外部联接(必需:false)包括相同的模型,因为内部联接由sequelize用于过滤器/限制/偏移,而外部联接用于排序。否则其中之一将引发missing FROM-clause entry for table "category"
错误。
但是,当我尝试以下操作时,sequelize似乎仅将后者添加到include []中。
有没有办法添加相同的模型:一个required: true
和另一个required: false
?
const { rows: posts,count } = await Post
.findAndCountAll({
where: {
$or: [
{ title: { $iLike: `%${searchKeyWord}%` } },{ '$category.label$': { $iLike: `%${searchKeyword}%` } },],},include: [
// needed for where to work
{ model: Category,required: true },// needed if i want to sort by category column
{ model: Category,required: false },{ model: Like },limit: 25,offset: 0,order: [['id','desc']],})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)