Lets say there are two models named as User and Post. A User hasMany Post, so in our User model we have a relation like this :-
class User extends AppModel{
var $name = User;
var $hasMany = array(Post=>array(foreignKey=>user_id));
}
Now whenever we use this model in our controller the above related model is also attached with user data.
Some times we may not want this data, to do that we can unbind the model in controller like this :-
$this->User->unbindModel(array(hasMany=>array(Post)));
To unbindModel permanently for within a controller function we just add false at the end of unbinding like this:-
$this->User->unbindModel(array(hasMany=>array(Post)),false);
This will unbind the model permanently for that action inside the controller.
0 Comment(s)