I try to use CakePHP 2 to execute model queries in vain. I’ve got 3 tables :
Code: php
An “Offer” table (An offer belongs to one “Place”)
A “Place” table (A “Place” has many offers) (A place belongs to one “City”)
A “City” table (A “City” has many “Place”)
I can’t manage to find the right syntax to get all the “Offers” from a specific “City” trouhg the “conditions” parameter.
Here what I tried. Code:
$this->set('offers', $this->Offer->find('all', array(
'conditions' => array('Place.City.name' => 'MyCity'),
'recursive' => 3)));
There is no problem with the model relations (“hasOne”, “blongsTo” etc.) because I can see the correct data using pr().
Do you have any idea?
Your offer model belongsTo place, so offer contains the foreignKey, therefore your condition should be:
or something like that. With place_id being the foreignKey you’re using of course.
Edit: oops, read to quick. You need the city instead of the place. I think you’ll need to bind models for this, see: http://mark-story.com/posts/view/using-bindmodel-to-get-to-deep-relations for more details.