mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Refactoring Model::__createLinks to not loose the plugin name when creating the association
This commit is contained in:
parent
4759b7adac
commit
91c3cd8905
1 changed files with 7 additions and 10 deletions
|
@ -601,19 +601,16 @@ class Model extends Object {
|
||||||
$this->{$type}[$assoc] = $value;
|
$this->{$type}[$assoc] = $value;
|
||||||
|
|
||||||
if (strpos($assoc, '.') !== false) {
|
if (strpos($assoc, '.') !== false) {
|
||||||
$value = $this->{$type}[$assoc];
|
list($plugin, $assoc) = pluginSplit($assoc);
|
||||||
unset($this->{$type}[$assoc]);
|
$this->{$type}[$assoc] = array('className' => $plugin. '.' . $assoc);
|
||||||
list($plugin, $assoc) = pluginSplit($assoc, true);
|
|
||||||
$this->{$type}[$assoc] = $value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$className = $assoc;
|
$className = $assoc;
|
||||||
|
|
||||||
if (!empty($value['className'])) {
|
if (!empty($value['className'])) {
|
||||||
list($plugin, $className) = pluginSplit($value['className'], true);
|
list($plugin, $className) = pluginSplit($value['className']);
|
||||||
$this->{$type}[$assoc]['className'] = $className;
|
|
||||||
}
|
}
|
||||||
$this->__constructLinkedModel($assoc, $plugin . $className);
|
$this->__constructLinkedModel($assoc, $className, $plugin);
|
||||||
}
|
}
|
||||||
$this->__generateAssociation($type);
|
$this->__generateAssociation($type);
|
||||||
}
|
}
|
||||||
|
@ -625,7 +622,7 @@ class Model extends Object {
|
||||||
*
|
*
|
||||||
* @param string $assoc Association name
|
* @param string $assoc Association name
|
||||||
* @param string $className Class name
|
* @param string $className Class name
|
||||||
* @deprecated $this->$className use $this->$assoc instead. $assoc is the 'key' in the associations array;
|
* @param string $plugin name of the plugin where $className is located
|
||||||
* examples: public $hasMany = array('Assoc' => array('className' => 'ModelName'));
|
* examples: public $hasMany = array('Assoc' => array('className' => 'ModelName'));
|
||||||
* usage: $this->Assoc->modelMethods();
|
* usage: $this->Assoc->modelMethods();
|
||||||
*
|
*
|
||||||
|
@ -634,13 +631,13 @@ class Model extends Object {
|
||||||
* @return void
|
* @return void
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __constructLinkedModel($assoc, $className = null) {
|
function __constructLinkedModel($assoc, $className = null, $plugin = null) {
|
||||||
if (empty($className)) {
|
if (empty($className)) {
|
||||||
$className = $assoc;
|
$className = $assoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->{$assoc}) || $this->{$assoc}->name !== $className) {
|
if (!isset($this->{$assoc}) || $this->{$assoc}->name !== $className) {
|
||||||
$model = array('class' => $className, 'alias' => $assoc);
|
$model = array('class' => $plugin . '.' . $className, 'alias' => $assoc);
|
||||||
$this->{$assoc} = ClassRegistry::init($model);
|
$this->{$assoc} = ClassRegistry::init($model);
|
||||||
if (strpos($className, '.') !== false) {
|
if (strpos($className, '.') !== false) {
|
||||||
ClassRegistry::addObject($className, $this->{$assoc});
|
ClassRegistry::addObject($className, $this->{$assoc});
|
||||||
|
|
Loading…
Reference in a new issue