You can use an array in the conditions:

'conditions' => array('Model.id' => $array)

...which does an 'IN' query, in which case you don't need to do the extracting 
etc.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 11 Feb 2011, at 21:14, rgreenphotodesign wrote:

> I changed the query to this and it works, but not sure it's very
> Cakeish
> 
> $conditions = array('Model.id IN ('.$stringOfIds.')');
> 
> On Feb 11, 2:01 pm, rgreenphotodesign <rgr...@rgreenphotography.com>
> wrote:
>> I've followed the example listed on [url]http://nuts-and-bolts-of-
>> cakephp.com/2008/05/13/build-a-string-from-a-resultset-array/[/url] to
>> build a string to pass to a find IN statement. All looks to work
>> expect it's encasing the new string in quotes. Here is what I have so
>> far using cake 1.3.7
>> 
>> [code]
>> $array = $this->ModelA->find->(‘all’, array($conditions));
>> $stringOfIds = implode(‘,’, Set::extract($array, ‘{n}.Model.id’));
>> $conditions = array(‘ModelB.modela_id’ => array($stringOfIds));
>> $this->data = $this->ModelB->find(‘all’, array(‘conditions’ =>
>> $conditions));
>> [/code]
>> This produces the following SQL
>> WHERE `Model`.`id` = (’1,19,186′)
>> It’s putting quotes around the new string an thus not producing the IN
>> query. I know it’s probably simple, but any ideas what’s causing this
>> or an easy way to escape the quotes?
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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

Reply via email to