cake-php@googlegroups.com
[Top] [All Lists]

Re: 3 models and search condition

Subject: Re: 3 models and search condition
From: viciat
Date: Sun, 13 Jun 2010 06:24:28 -0700 PDT
Solution
After reading this:
http://bakery.cakephp.org/articles/view/get-the-find-query-sql-rather-than-query-result

First get the id's of the locations from the offers corresponding to a
certain category

                                $this->Offer->recursive = 0;
                                $options = array(
                                    'conditions' => array(
                                        'Offer.category_id' => $id),
                                    'fields' => 'Offer.location_id',
                                    'recursive' => -1
                                );
                                $location_ids = 
$this->Offer->find("sql",$options);
                                
Than get the actual locations
                                $location_options = array(
                                    'conditions' => array(
                                        'Location.id IN ('.$location_ids.')'
                                    ),
                                    'contain' => 
array('Offer','LocationsPicture')
                                );                                              
           
                           $locations = $this->Location->find('all', 
$location_options);
                           $this->set('locations',$locations);
-- 
View this message in context: 
http://old.nabble.com/3-models-and-search-condition-tp28866040p28871272.html
Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
cake-php+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

<Prev in Thread] Current Thread [Next in Thread>