If we have to many tables in our project and we have many association between them. So whenever we use one of the model in our controller the other model which are associated with it , automatically get attached with user data .
Sometime we don't want this data, for that purpose we use unBind function for unbinding models.
Below is the example in which country model is associated with state model by hasMany relationship. So whenever we use country model in our controller the state model which are associated with it , automatically get attached with user data .
class Country extends AppModel {
public $hasMany = array(
'State' => array(
'className' => 'State',
),
);
}
Below is the logic for unbinding models.
public function unBind(){
$this->Country->unBindModel(array('hasMany'=>array('State')));
$data = $this->Country->find("all", array('limit'=>4));
}
To unbindModel permanently we have to add false with unbind function.
$this->Country->unBindModel(array(hasMany=>array('State')),false);
0 Comment(s)