我正在构建条件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
时,查询被破坏,我收到了未知的列错误
即
{
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] ] } }