How to fetch deep associations with CakePHP's find operations? -
i building website has 3 models: store, storereview, , user. website lists stores, , users can review stores. therefore, store model can have many storereview rows, , each storereview row belongs user row.
my question is: when fetching store rows, how can fetch relevant user along storereview rows? i'm using:
<?php class storescontroller extends appcontroller {      public function view($slug) {         $stores = $this->store->find('all');     } } but returns 'storereview' rows. because user row level deeper, i'm unsure how fetch this; i've checked cakephp's documentation , googled, cakephp have re-jigged documentation site, , samples on websites google search didn't work.
thank in advance.
there 2 ways. can increase recursive attribute:
$stores = $this->store->find('all', array('recursive' => 2)); or use containable behavior (i prefer since can make more 2 levels):
$this->store->behaviors->attach('containable'); $this->store->contain(array('storereview' => array('user'))); $stores = $this->store->find('all'); $this->store->behaviors->detach('containable'); more informations:
Comments
Post a Comment