CakePHP .find to return multiple HABTM relationships -
i have model phone call playlist. playlist has habtm track
public $hasandbelongstomany = array( 'track' => array( 'classname' => 'track', 'jointable' => 'tracklists_tracks', 'foreignkey' => 'tracklist_id', 'associationforeignkey' => 'track_id', 'unique' => 'keepexisting', 'conditions' => '', 'fields' => array('id','title','version'), 'order' => 'trackliststrack.timing' ) ); track has habtm appuser
public $hasandbelongstomany = array( 'artist' => array( 'classname' => 'appuser', 'jointable' => 'artists_tracks', 'foreignkey' => 'track_id', 'associationforeignkey' => 'artist_id', 'unique' => 'keepexisting', 'conditions' => '', 'fields' => array('id','username') ) ); now, like, when write this
$tracklist = $this->tracklist->findbyid($id);
to each tracklist tracks (and work supposed to), , every tracks appusers (cascading).
mind if write $this->track->findbyid($id); can appusers related track
any thought have out of box diligent naming convention ?
thank you
if have define right relationship in model, suggest using cakephp containable behavior.
http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
all need include behavior in model , set next in controller
$this->tracklist->contain(array('appuser','artist')); cakephp
No comments:
Post a Comment