Re: Problem with find condition and array
Hi, yes, you are on right track... this is how you should do it $audios = $this->Audioplaylist->Audio->find('all', array('conditions' => array('Audio.id' => $audioIds) ) ); This will translate to Audio.id IN (1, 2, 3) Your problem might be because of your array. Make sure your array $audioIds is one dimensional array V On Aug 28, 1:50 pm, schneimi wrote: > Hi, > > I have an array with some ids of a model and struggle with getting > them into a find condition. > > This is what I currently use, it works but is not very caky: > > $audioIds = array('1', '2', '3',); > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > => 'Audio.id='.implode(' OR Audio.id=', $audioIds))); > > I think it should look like this the cake way: > > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > => array('Audio.id' => $audioIds))); > > but this results in [...] AND `Audio`.`id`=Array [...] > > I already had a look into the cookbook and played around alot, but > couldn't figure out a proper way, so I hope you can help me. > > Thx, > Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with find condition and array
Hi, thx for the answers! I just found the problem, the array is ok as is the find, the problem is caused by one of my behaviors where I the condition is influenced. Funny that just yesterday something similar happened to one guy on irc channel I tried to help with non working pagination. Never trust a behavior, least the own ones. ;-) Michael On 28 Aug., 11:47, Vishal G wrote: > Hi, > > yes, you are on right track... this is how you should do it > > $audios = $this->Audioplaylist->Audio->find('all', > array('conditions' => array('Audio.id' => $audioIds) ) > ); > > This will translate to Audio.id IN (1, 2, 3) > > Your problem might be because of your array. > > Make sure your array $audioIds is one dimensional array > > V > > On Aug 28, 1:50 pm, schneimi wrote: > > > Hi, > > > I have an array with some ids of a model and struggle with getting > > them into a find condition. > > > This is what I currently use, it works but is not very caky: > > > $audioIds = array('1', '2', '3',); > > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > > => 'Audio.id='.implode(' OR Audio.id=', $audioIds))); > > > I think it should look like this the cake way: > > > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > > => array('Audio.id' => $audioIds))); > > > but this results in [...] AND `Audio`.`id`=Array [...] > > > I already had a look into the cookbook and played around alot, but > > couldn't figure out a proper way, so I hope you can help me. > > > Thx, > > Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Problem with find condition and array
I have used array assignment before and it works perfectly : // General conditions for the query $conditions = array( 'Institute.conversions' => 'yes', 'Institute.brochure_pay_amount >' => 0, 'Training.id' => $highestRatedTrainingIds, '1 = 1 GROUP BY Training.id' ); Sorry that I can't tell you why it fails :-/ On Fri, Aug 28, 2009 at 10:50 AM, schneimi wrote: > > Hi, > > I have an array with some ids of a model and struggle with getting > them into a find condition. > > This is what I currently use, it works but is not very caky: > > $audioIds = array('1', '2', '3',); > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > => 'Audio.id='.implode(' OR Audio.id=', $audioIds))); > > I think it should look like this the cake way: > > $audios = $this->Audioplaylist->Audio->find('all', array('conditions' > => array('Audio.id' => $audioIds))); > > but this results in [...] AND `Audio`.`id`=Array [...] > > I already had a look into the cookbook and played around alot, but > couldn't figure out a proper way, so I hope you can help me. > > Thx, > Michael > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Problem with find condition and array
Hi, I have an array with some ids of a model and struggle with getting them into a find condition. This is what I currently use, it works but is not very caky: $audioIds = array('1', '2', '3',); $audios = $this->Audioplaylist->Audio->find('all', array('conditions' => 'Audio.id='.implode(' OR Audio.id=', $audioIds))); I think it should look like this the cake way: $audios = $this->Audioplaylist->Audio->find('all', array('conditions' => array('Audio.id' => $audioIds))); but this results in [...] AND `Audio`.`id`=Array [...] I already had a look into the cookbook and played around alot, but couldn't figure out a proper way, so I hope you can help me. Thx, Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---