N.Schipper
N.Schipper

Reputation: 1668

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

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.

Upvotes: 0

Views: 862

Answers (1)

spekulatius
spekulatius

Reputation: 1499

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();

Upvotes: 2

Related Questions