has and belongs to many - cakephp HABTM and dependency upon another foreign model -
i have resource habtm room. room model depends on model building. how can integrate dependency?
class resource extends appmodel { public $hasandbelongstomany = array('room' => array( 'conditions' => array('room.building_id = building.id'), ) ); } class room extends appmodel { public $belongsto = array('building'); public $hasandbelongstomany = array('resource'); public $virtualfields = array( 'name' => 'concat(building.short, room.floor, ".", room.number)' );
in model , belongsto linking did way:
public function beforefind($query) { parent::beforefind($query); $this->bindmodel(array( 'belongsto' => array( 'room' => array( 'foreignkey' => false, 'conditions' => array('booking.room_id = room.id') ), 'building' => array( 'foreignkey' => false, 'conditions' => array('room.building_id = building.id') ) ) )); }
but have no clue how bind/add building model ressource model. have add resource model working?
thanks in advance!
Comments
Post a Comment