Hi, I had a very similar setup and the same problem. Here is how I would solve your problem:
Since you are not giving away most of your code, I make some assumptions:
- You have implemented your search method in BusinessController
- Your search argument for the city is stored in vaiable $, where for the category is stored in $ what
Code if you only have conditions for one table
$this->Businesses->Town->recursive = -1; .... $options['joins'] = array( array('table' => 'towns', 'alias' => 'Town', 'type' => 'inner', 'conditions' => array( 'Business.town_id = Town.id', ) ) ); $options['conditions'] = array( 'Town.townName' => $where ); $result = $this->Business->find('all', $options);
Code if you have conditions for two tables
$this->Businesses->Town->recursive = -1; $this->Businesses->Category->recursive = -1; .... $options['joins'] = array( array('table' => 'towns', 'alias' => 'Town', 'type' => 'inner', 'conditions' => array( 'Business.town_id = Town.id', ) ), array('table' => 'categories', 'alias' => 'Category', 'type' => 'inner', 'conditions' => array( 'Business.category_id = category.id', ) ) ); $options['conditions'] = array( 'Town.townName' => $where, 'Category.categoryName' => $what ); $result = $this->Business->find('all', $options);
David source share