Hi,

> I have two models Vehicles and City. I want to FindAll Vehicles where
> City.Province_id = 3. The problem is, Vehicle is related to city via
> another table, "businesses" like so:
>
> Vehicle $belongsTo Business $belongsTo City $belongsTo Province
>
> or in the other direction:
>
> Province $hasMany City $hasMany Business $hasMany Vehicle

I tihnk you might want to try unbinding your Buiness and City model,
then binding it again, adding a Condition to only retrieve Businesses
for a certain city, eg:

// unbind association
$this->Vehicle->Business->unbindModel (array('belongsTo'=>array('City')));
// create new association
$this->Vehicle-> Business ->bindModel(array('belongsTo'=>array('City '
=>array('className'=>'City ', 'conditions' => 'City.province_id = ' .
$province_id))));
// fetch vehicles
$this->Vehicle->findAll ();

The above is untested!

One thing to remember is this technique does not reduce your SQL
queries, though it does limit the data that's returned.

I'm sure there are other techniques, only one else wanna chip in?

Also very interested in peoples opinions of this technique.

Cheers,

Jon

-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" 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