Have a look at the 'matches' example here:

http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find

On Sun, May 17, 2009 at 11:18 AM, foldiman <[email protected]> wrote:
>
> I'm stuck on constructing a complex find statement. I have a Car model
> and a Cartype model that are associated via HABTM. In other words, a
> Jeep (Car) can be an SUV (Cartype), a Truck (Cartype), and a
> Convertible (Cartype).
>
> I'm stuck on constructing the find query when searching for Cars by
> Cartype. If the relationship WAS Cartype HasMany Car (ie. a Car can
> only have one Cartype) it would be easy....
>
> $search_criteria = array('SUV', 'Truck', 'Convertible');
>
> $params = array(
>     'conditions' = array('Car.cartype_id' => $search_criteria);
> )
>
> $this->Car->find('all', $params);
>
> BUT, the Car model can have many Cartypes...meaning the Car model does
> not have a `cartype_id` field.
>
> So how do construct a query that would mean, "give me all the Cars
> that are related to at least one Cartype contained in the search
> criteria"? Does this make sense?
>
> Thanks.
> >
>

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

Reply via email to