使用include进行顺序搜索

时间:2019-01-31 01:45:05

标签: node.js electron sequelize.js

我想用Sequelize进行查询,该查询使用jquery返回包含变量中内容的行。

我的代码:

var db = require('../../config/db')
var City= db.sequelize.import('./models/city')
var District = db.sequelize.import('./models/district')
var Address = db.sequelize.import('./models/address')
var User = db.sequelize.import('./models/user')

Address.belongsTo(District,{foreignKey:'district_id'})
District.belongsTo(City,{foreignKey:'city_id'})
User.belongsTo(Address,{foreignKey:'address_id'})

我想要这样的查询:(此代码不起作用)

运行时出现此错误:

SequelizeDatabaseError:'where子句'中的未知列'district.bairro.nome'

   var paramsSearch = {
      offset: offset, limit: limit_records,       
      include:[{model:District, include:[{District, include:[{model: City}]}]}],
      where: {      
        [Op.or]: [
         {'users.user_name': db.sequelize.where(db.sequelize.fn('LOWER', db.sequelize.col('users.user_name')), 'LIKE', '%' + search + '%')},
         {'address.name': db.sequelize.where(db.sequelize.fn('LOWER', db.sequelize.col('address.name')), 'LIKE', '%' + search + '%')},
         {'address.district.name': db.sequelize.where(db.sequelize.fn('LOWER', db.sequelize.col('addrress.district.name')), 'LIKE', '%' + search + '%')}
        ]
      }   
    }

    Cliente.findAll(paramsSearch)
                .then(results=>{
                    console.log(results) 
                }

有人可以帮助我吗?

0 个答案:

没有答案