Strongloop: filter data with [and] and [or] conditions together

那年仲夏 提交于 2021-02-19 06:00:35

问题


I'm trying to filter data using "and" and "or" conditions. I would like to get this mySql query:

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

The rest api that I wrote is like this:

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

The loopback json translation seems to be correct:

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

But the translated query on mySql is:

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

What is wrong?


回答1:


The correct filter is like :

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


来源:https://stackoverflow.com/questions/38262282/strongloop-filter-data-with-and-and-or-conditions-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!