Silverstripe combine filterAny and filter to have an OR with an AND in it

情到浓时终转凉″ 提交于 2019-12-25 03:56:07

问题


I have a question and maybe somebody can help me figure out what the best way would be to achieve the solution. What i wanted to do is the reverse of:

http://doc.silverstripe.com/framework/en/topics/datamodel#highlighter_745635

WHERE ("LastName" = 'Minnée' AND ("FirstName" = 'Sam' OR "Age" = '17'))

I want to get something along the lines of:

WHERE( ("LastName" = 'Minnée') OR ("FirstName" = 'Sam' AND "Age" = '17'))

Now i cannot find any way to achieve this effect seeing as i cannot add a filter within the filterAny

For now i am doing it with the get()->where( ... ) option but was more wondering with this question if their are alternative options without having to write normal SQL code.


回答1:


As 'AND' has a higher priority it doesn't need to be in braces. You can just write it as:

WHERE( "LastName" = 'Minnée' OR "FirstName" = 'Sam' AND "Age" = '17')

But as far as I can tell on the first look there isn't a way to write this without using where(). Let us know if you find a way. For debuging you can display the generated SQL-Query by calling the function sql():

... get()->where( ... )->sql();


来源:https://stackoverflow.com/questions/25475089/silverstripe-combine-filterany-and-filter-to-have-an-or-with-an-and-in-it

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