sequelize limit和order不适用于条件查询

qlckcl4x  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(262)

我正在构建一个条件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&&params.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] ] } }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题