Has anyone noticed behaviors on AppModel are being added twice to
models in plugins?


For example, if I have:

AppModel {
$actsAs = array(A, B, C)
}

PluginAppModel extends AppModel{
// ...no actsAs
}

PluginModel extends PluginAppModel{
// ... no actsAs
}

Then cake will add an $actsAs to PluginModel as follows:

$actsAs = array(A,B,C,A,B,C);

It adds the behaviors twice.

The problem seems to be in cake v1.3.6, cake/libs/model/model.php,
lines: 443 - 464, as follows:

if (is_subclass_of($this, 'AppModel')) {
                        $appVars = get_class_vars('AppModel');
                        $merge = array('_findMethods');

                        if ($this->actsAs !== null || $this->actsAs !== false) {
                                $merge[] = 'actsAs';
                        }
                        $parentClass = get_parent_class($this);
                        if (strtolower($parentClass) !== 'appmodel') {
                                $parentVars = get_class_vars($parentClass);
                                foreach ($merge as $var) {
                                        if (isset($parentVars[$var]) && 
!empty($parentVars[$var])) {
                                                $appVars[$var] = 
Set::merge($appVars[$var], $parentVars[$var]);
                                        }
                                }
                        }

                        foreach ($merge as $var) {
                                if (isset($appVars[$var]) && 
!empty($appVars[$var]) &&
is_array($this->{$var})) {
                                        $this->{$var} = 
Set::merge($appVars[$var], $this->{$var});
                                }
                        }
                }


In the code above:

$appVars - the AppModel's instance vars.
$parentVars - the PluginAppModel's instance vars.
$this - the plugin model.


The line:
$appVars[$var] = Set::merge($appVars[$var], $parentVars[$var]);

...merges the $actsAs from PluginAppModel with the $actsAs from
AppModel.

Since PluginAppModel inherits from AppModel, the
get_class_vars($parentClass) will always yield the same instance vars
that AppModel has, leading to always doubling them up.

Has anyone else noticed this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to