Sailsjs Mysql ORM multiple query on the same table field

岁酱吖の 提交于 2019-12-02 04:57:38

In order to do this based on how waterline works you need different fields to search on.

You can do this by created aliased attributes in your model.

venue.js
module.exports.attributes = {
    restaurant_services:'string',
    restaurant_services_1: {type:'string',columnName: 'restaurant_services'}
    restaurant_services_2: {type:'string',columnName: 'restaurant_services'}
    restaurant_services_3: {type:'string',columnName: 'restaurant_services'}
    restaurant_services_4: {type:'string',columnName: 'restaurant_services'}
    restaurant_services_5: {type:'string',columnName: 'restaurant_services'}
}

Then you can do

Venue.find().populate('comments', {
        deleted: false
    }).where({
            restaurant_services: {contains: '"delivery":1'},
            restaurant_services_1: {contains: '"takeout":1'},
            restaurant_specialties: {contains: '"breakfast":1'}
    })

Its hacky, but it works

Venue.find().populate('comments', {
    deleted: false
}).where({
        restaurant_services: {
            contains: '"delivery":1',
            contains: '"takeout":1',
        },
        restaurant_specialties: {contains: '"breakfast":1'}
})

that you need

Venue.find({
  where:{
    restaurant_services: {
      contains: '"delivery":1',
      contains: '"takeout":1',
    },
    restaurant_specialties: {
      contains: '"breakfast":"1"'
    }
  }
}).populate('comments', {
    deleted: false
}).exec(console.log);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!