Im using sails v 0.10.5 and latest sails-mysql

我使用sails v 0.10.5和最新的sails-mysql

I have a Restaurant filtering system

我有一个餐厅过滤系统

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

Now the problem is when I get the data from the client, I do not know how many items the user has selected for restaurat_services, so obviously I have to create a dynamic JSON object for the .where() function

现在问题是当我从客户端获取数据时,我不知道用户为restaurat_services选择了多少项,所以很明显我必须为.where()函数创建一个动态JSON对象

The problem is though, I cannot do this

问题是,我不能这样做

var searchObj = {};
searchObj['restaurant_specialties'] = {contains: '"breakfast":1'}; 

searchObj['restaurant_specialties'] = {contains: '"breakfast":1'};

searchObj ['restaurant_specialties'] = {contains:'“breakfast”:1'};

So as you may see the previous setting of the value gets replaced the second time,

因此,您可能会看到第二次替换以前的值设置,

Any help would be greatly appreciated from the Smart people out therehere but does not work

任何帮助都会受到Smart People的青睐,但不起作用

Model.find({
  name: { 'contains' : ['Walter', 'Skyler'] }
});

2 个解决方案

#1


1

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

它的hacky,但它的工作原理

更多相关文章

  1. SQL表的简单操作
  2. MySQL数据操作之多表查询
  3. DBExportDoc V1.0 For MySQL Windows64位操作系统导出mysql表结
  4. 数据库_6_SQL基本操作——库操作
  5. Linux操作系统Centos7.2版本搭建Apache+PHP+Mysql环境
  6. 常用的hive-sql操作命令(1)
  7. 操作MySQL,使用ezSQL,简单而方便
  8. linux下使用c++语言对mysql数据库操作
  9. 关于使用框架操作Oracle数据库切换MySQL数据库时,nextval的问题!

随机推荐

  1. Android* 操作系统上的应用程序远程调试
  2. Android(安卓)studio查看sdk源代码
  3. 参数设置
  4. android开机启动的问题,android:installLo
  5. Android修改Eclipse 中的Default debug k
  6. Android环境安装
  7. Android的日志系统分层与logcat使用
  8. Android: JAVA和C# 3DES加密解密
  9. Android(安卓)EditText实现字符过滤
  10. Android 多个Activity选项卡实现