Reputation: 65
I have a simple problem and I haven't found an answer. I need to do a query with IN operator from MySql.
I've tried to use this sintax:
$this->Client->find("all",array("conditions"=>
array("ClientRelCelula.rec_cel_codigo IN"=>$celula)
but the condition WHERE is so
WHERE `ClientRelCelula`.`rec_cel_codigo` IN = ('2')
I found the error, when i retreat the equal ( = ) the query works fine.
Thank you!
Upvotes: 2
Views: 3432
Reputation: 3273
You don't need the IN
in the condition. If the passed data is an array, Cake will make it an IN
For instance:
$celula = 2;
$this->Client->find("all",array("conditions"=>
array("ClientRelCelula.rec_cel_codigo"=>$celula);
Will Produce:
WHERE `ClientRelCelula`.`rec_cel_codigo` = 2
And this:
$celula = array(2, 3, 4);
$this->Client->find("all",array("conditions"=>
array("ClientRelCelula.rec_cel_codigo"=>$celula);
Will Produce:
WHERE `ClientRelCelula`.`rec_cel_codigo` IN (2,3,4)
Upvotes: 4