Ok let's try debugging to fix this.
Also can you send me the calls you are using (i.e: from your first call to
your expects() to later findAll() or whatever call)?
Use this as your expects() method and put an exit or a die() just before you
do your findAll() so you can write down the results, send them after doing
that:
function expects()
{
$models = array();
$arguments = func_get_args();
foreach($arguments as $index => $argument)
{
if (is_array($argument))
{
if (count($argument) > 0)
{
$arguments = array_merge($arguments,
$argument);
}
unset($arguments[$index]);
}
}
if (count($arguments) == 0)
{
$models[$this->name] = array();
}
else
{
foreach($arguments as $argument)
{
if (strpos($argument, '.') !== false)
{
$model = substr($argument, 0,
strpos($argument, '.'));
$child = substr($argument,
strpos($argument, '.') + 1);
if ($child == $model)
{
$models[$model] = array();
}
else
{
$models[$model][] = $child;
}
}
else
{
$models[$this->name][] = $argument;
}
}
}
echo $this->name . '.models (all): <pre>'; print_r($models);
echo '</pre>';
foreach($models as $model => $children)
{
if ($model != $this->name && isset($this->$model))
{
echo 'CALLING ' . $model . '.expects() with
<pre>'; print_r($children); echo '</pre>';
$this->$model->expects($children);
}
}
if (isset($models[$this->name]))
{
foreach($models as $model => $children)
{
if ($model != $this->name)
{
$models[$this->name][] = $model;
}
}
$models = array_unique($models[$this->name]);
echo $this->name . '.models: <pre>';
print_r($models); echo '</pre>';
$unbind = array();
$relations = array ('belongsTo', 'hasOne',
'hasMany', 'hasAndBelongsToMany');
foreach($relations as $relation)
{
if (isset($this->$relation))
{
foreach($this->$relation as
$currentModel)
{
$currentModelClass =
(isset($currentModel['className']) ? $currentModel['className'] :
$currentModel['classname']);
if
(!in_array($currentModelClass, $models))
{
$unbind[$relation][]
= $currentModelClass;
}
}
}
}
if (count($unbind) > 0)
{
$this->unbindModel($unbind);
}
}
}
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Mikee Freedom
Enviado el: Lunes, 18 de Diciembre de 2006 08:22 p.m.
Para: [email protected]
Asunto: Re: Keeping unbindModel out of your controllers
Using the new method returns the same result unfortunately.
Is it how I've defined my associations maybe? Is that not the proper
definition for parent - child?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---