【问题标题】:Strongloop: filter data with [and] and [or] conditions togetherStrongloop:用 [and] 和 [or] 条件一起过滤数据
【发布时间】:2016-07-11 16:08:23
【问题描述】:

我正在尝试使用“and”和“or”条件过滤数据。 我想得到这个 mySql 查询:

SELECT * FROM `data` WHERE ((`property1`=11) OR (`property1`=13)) AND (`property2`=6)

我写的其余api是这样的:

http://localhost:4000/api/Data/?filter[where][or][0][property1]=11&filter[where][or][1][property1]=13&filter[where][and][0][property2]=6

loopback json 翻译似乎是正确的:

{                                            
    "or": [                              
            {                            
                    "property1": 11      
            },                           
            {                            
                    "property1": 13      
            }                            
    ],                                   
    "and": [                             
            {                            
                    "property2": 6     
            }                            
    ]                                    
}

但是mySql上的翻译查询是:

SELECT * FROM `data` WHERE (`property1`=11) OR (`property1`=13) AND (`property2`=6)

怎么了?

【问题讨论】:

  • 需要将or封装成and。

标签: mysql node.js strongloop


【解决方案1】:

正确的过滤器是这样的:

{     
    "and": [
        {                            
          "property2": 6     
        } ,
        {
        "or": [                              
            {                            
                    "property1": 11      
            },                           
            {                            
                    "property1": 13      
            }                            
    ]   }    
    ]                              
}

【讨论】:

  • 谢谢易卜拉欣。 json结构很清楚,但是我不明白如何从api rest调用中获取这个json。
  • @FrancescoDeRosa 也许filter[where][and][0][or][0][property1]=11&filter[where][and][0][or][1][property1]=13&filter[where][and][1][property2]=6
猜你喜欢
  • 1970-01-01
  • 2018-12-25
  • 2020-04-17
  • 1970-01-01
  • 2016-04-21
  • 1970-01-01
  • 2021-10-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多