unbind All associations except some
Saturday, June 3rd, 2006This is a very handy method ( in your AppModel ).
Many times you have a model that has a lot of associations, and for some stuff, you don’t want the overhead of all the associated data. For that you use $this->recursive = ‘-1′, this turns all associations completly. or you can use calls to unbindModel. but then sometimes, you don’t know what associations the model has ( ie. a piece of code you wrote that is used by other people, a component most likely ).
for that there is unbindAll, this method will shut off all associations except the ones passed in params, usage:
-
-
$this->Special->Product->unbindAll(array(‘belongsTo’=>array(‘Category’,‘Manufacturer’),‘hasMany’=>array(‘Image’)));
Neat eh ? here is the code:
-
{
-
foreach($this->__associations as $ass)
-
{
-
{
-
$this->__backAssociation[$ass] = $this->{$ass};
-
{
-
foreach($this->{$ass} as $model => $detail)
-
{
-
{
-
}
-
}
-
}else
-
{
-
}
-
-
}
-
}
-
return true;
-
}
-