How does unbindModel happen in cake?
$this->User->unbindModel(array(\'hasAndBelongsToMany\' => array(\'Friend\')));
I wrote this i
From the manual:
Removing or adding associations using bind- and unbindModel() only works for the next model operation unless the second parameter has been set to
false
. If the second parameter has been set tofalse
, the bind remains in place for the remainder of the request.
In other words, after you paginate()
or find()
or do anything else with the model, the unbinding will be reversed.
Well, in my experience with unbinds, I can say Paginate always do 2 querys one for count the total and the second for the result array
unbind destroy just once time the relation and yea you need extend this rule to destroy two or more times so you need to set TRUE I guess to persist this rule:
$this->User->unbindModel(array('hasAndBelongsToMany' => array('Friend')), true);
Try This:
$this->Leader->find('all');
// Let's remove the hasMany...
$this->Leader->unbindModel(
array('hasMany' => array('Follower'))
);
// Now using a find function will return
// Leaders, with no Followers
$this->Leader->find('all');
// NOTE: unbindModel only affects the very next
// find function. An additional find call will use
// the configured association information.
// We've already used find('all') after unbindModel(),
// so this will fetch Leaders with associated
// Followers once again...
$this->Leader->find('all');