Wednesday, April 3, 2013

Re: Problem with nested AND / OR Condition

It's been awhile since I had to do any complicated AND/OR stuff but I think this would work:

$options = array(
'conditions' => array(
'OR' => array(
'id' => 1,
array(
'AND' => array(
'column1' => 'test1',
'id' => 2
)
),
array(
'AND' => array(
'column1' => 'test2',
'id' => 3
)
)
)
)
);

I think this should be equivalent:

$options = array(
'conditions' => array(
'OR' => array(
'id' => 1,
array(
'column1' => 'test1',
'id' => 2
),
array(
'column1' => 'test2',
'id' => 3
)
)
)
);


On Fri, Mar 29, 2013 at 10:02 PM, Carsten Wawer <carsten.wawer@gmail.com> wrote:
Hey Folks

maybe I'm just at a loss, but how do I create a SQL command like this with cakePHP?

SELECT *
FROM table
WHERE id = 1 OR (column1='test1' AND id=2) OR (column1='test2' AND id=3)


Please do not ask about the meaning, I have simplified a more complex command to make the problem clear.

The Condition would have to actually something like this:


$options = array(
'conditions' => array(
'OR' => array(
'id' => 1,
'AND' => array(
'column1' => 'test1',
'id' => 2
),
'AND' => array(
'column1' => 'test2',
'id' => 3
)
)
)
);

But the second 'AND' overrwrites the first one.

Can someone give me a hint? I would be grateful! ;-)

Greetings!
Carsten

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: