Sailsjs Mysql ORM multiple query on the same table field

前端 未结 2 1030
予麋鹿
予麋鹿 2021-01-23 17:48

Im using sails v 0.10.5 and latest sails-mysql

I have a Restaurant filtering system

Venue.find().populate(\'comments\', {
        deleted: false
    }).w         


        
2条回答
  •  灰色年华
    2021-01-23 18:32

    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

提交回复
热议问题