问题
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