续订限制和顺序不适用于条件查询

时间:2018-05-28 11:14:50

标签: mysql express sequelize.js

我正在构建条件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);

但是当我添加limitoffset时,查询被破坏,我收到了未知的列错误

{    
       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] ] } }

0 个答案:

没有答案