我正在构建一个条件orm查询
let defaultWhere ={
isPublic:1
};
//query to build
let query = {
distinct:true,
include:[
{
model:DealsMeta,
where:{
type:'view'
},
as: "totalviews",
attributes: ['id'],
required:false,
},
{
model:DealsTransactions,
as: "totaltransactions",
attributes: ['id'],
required:false
}
]
};
let keywordWhere = {};
//add the search parameter
if(params.keyword!=undefined&¶ms.keyword!=""){
keywordWhere = {
[Op.or]:[
{title: { $like: '%' + params.keyword + '%' }},
{keywords: { $like: '%' + params.keyword + '%' }},
Sequelize.where(Sequelize.fn('concat_ws', Sequelize.col('firstName'), ' ', Sequelize.col('lastName')), {
$like: '%' + params.keyword + '%'
})
]
};
query.include=query.include.concat({ model:User, required:false,attributes:['firstName'] })
}
query.where=Object.assign(defaultWhere,keywordWhere);
但当我加上 limit
以及 offset
查询已中断,出现未知列错误
ie公司
{
distinct:true,
offset:0,
limit:2
}
返回中断的查询
更新
最终查询
{ distinct: true,
order: [ [ 'idDeal', 'DESC' ] ],
limit: 2,
offset: 0,
include:
[ { model: deals_metadata,
where: [Object],
as: 'totalviews',
attributes: [Array],
required: false },
{ model: deals_transactions,
as: 'totaltransactions',
attributes: [Array],
required: false },
{ model: USER, required: false, attributes: [Array] } ],
where: { isPublic: 1, [Symbol(or)]: [ [Object], [Object], [Where] ] } }
暂无答案!
目前还没有任何答案,快来回答吧!