Hi all,
How can I achieve the following result in cakephp:
In my application a Topic is related to category, category is related to city and city is finally related to state
in other words:
topic belongs to category, category belongs to city , city belongs to state..
Now in the Topic controller's index action I want to find out all the topics and it's city and state.
How can I do this.
I can easily do this using a custom query ($this->Model->query() function ) but then I will be facing pagination difficulties.
I tried doing like this
function index()
{
$this->Topic->recursive = 0;
$topics = $this->paginate();
for($i=0; $i<count($topics);$i++)
{
$topics[$i]['City'] = $this->Topic->Category->City->find('all', array('conditions' => array('City.id' => $topics[$i]['Category']['city_id'])));
}
$this->set(compact('topics'));
}
The method that I have adopted is not a good one (running query in a loop)
Using the recursive property and setting it to highest value (2) will degrade performance and is not going to yield me state information.
How shall I solve this ?
Please help
Thanks