From fc54b0f31abb061326f6df1417e8c22e96b98b7b Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 14 Sep 2006 21:59:51 +0000 Subject: [PATCH] Adding fix for #1165. Changing Model::__constructLinkedModel() to use the association name for the instance of an associated model. Changed DboSource::read() to use the association name. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3484 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 8 ++++---- cake/libs/model/datasources/dbo_source.php | 4 ++-- cake/libs/model/model.php | 24 +++++++++++++--------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index f8951d2c9..de5802e9f 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -351,7 +351,7 @@ class Controller extends Object { } } /** - * Redirects to given $url, after turning off $this->autoRender. Please notice that the script execution is not stopped + * Redirects to given $url, after turning off $this->autoRender. Please notice that the script execution is not stopped * after the redirect. * * @param string $url @@ -630,7 +630,7 @@ class Controller extends Object { $model = $this->modelClass; $modelKey = $this->modelKey; $table = $this->{$model}->table; - $association = array_search($table, $this->{$model}->alias); + //$association = array_search($table, $this->{$model}->alias); $objRegistryModel =& ClassRegistry::getObject($modelKey); foreach($objRegistryModel->_tableInfo as $tables) { @@ -644,7 +644,7 @@ class Controller extends Object { } $fkNames = $this->{$model}->keyToTable[$tabl['name']]; $fieldNames[$tabl['name']]['table'] = $fkNames[0]; - $association = array_search($fieldNames[$tabl['name']]['table'], $this->{$model}->alias); + //$association = array_search($fieldNames[$tabl['name']]['table'], $this->{$model}->alias); $fieldNames[$tabl['name']]['prompt'] = Inflector::humanize($niceName); $fieldNames[$tabl['name']]['model'] = $fkNames[1]; $fieldNames[$tabl['name']]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']]; @@ -702,7 +702,7 @@ class Controller extends Object { } } } - $fieldNames[$tabl['name']]['selected'] = $data[$association][$tabl['name']]; + $fieldNames[$tabl['name']]['selected'] = $data[$model][$tabl['name']]; } } else { $fieldNames[$tabl['name']]['type'] = 'input'; diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 24a0d1ed3..2bb0d5c0d 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -526,7 +526,7 @@ class DboSource extends DataSource { foreach($model->__associations as $type) { foreach($model->{$type} as $assoc => $assocData) { if ($model->recursive > -1) { - $linkModel =& $model->{$assocData['className']}; + $linkModel =& $model->{$assoc}; if ($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null)) { @@ -557,7 +557,7 @@ class DboSource extends DataSource { foreach($model->__associations as $type) { foreach($model->{$type} as $assoc => $assocData) { $db = null; - $linkModel =& $model->{$assocData['className']}; + $linkModel =& $model->{$assoc}; if (!in_array($type . '/' . $assoc, $linkedModels)) { if ($model->useDbConfig == $linkModel->useDbConfig) { diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index e5d10449f..0dabf7b17 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -554,21 +554,25 @@ class Model extends Overloadable { if (ClassRegistry::isKeySet($colKey)) { if (!PHP5) { - $this->{$className} =& ClassRegistry::getObject($colKey); + $this->{$assoc} =& ClassRegistry::getObject($colKey); + $this->{$className} =& $this->{$assoc}; } else { - $this->{$className} = ClassRegistry::getObject($colKey); + $this->{$assoc} = ClassRegistry::getObject($colKey); + $this->{$className} = $this->{$assoc}; } } else { if (!PHP5) { - $this->{$className} =& new $className($id, $table, $ds); + $this->{$assoc} =& new $className($id, $table, $ds); + $this->{$className} =& $this->{$assoc}; } else { - $this->{$className} = new $className($id, $table, $ds); + $this->{$assoc} = new $className($id, $table, $ds); + $this->{$className} = $this->{$assoc}; } } - $this->alias[$assoc] = $this->{$className}->table; - $this->tableToModel[$this->{$className}->table] = $className; - $this->modelToTable[$className] = $this->{$className}->table; + $this->alias[$assoc] = $this->{$assoc}->table; + $this->tableToModel[$this->{$assoc}->table] = $assoc; + $this->modelToTable[$assoc] = $this->{$assoc}->table; } /** * Build array-based association from string. @@ -580,9 +584,9 @@ class Model extends Overloadable { foreach($this->{$type} as $assocKey => $assocData) { $class = $assocKey; - if (isset($this->{$type}[$assocKey]['className']) && $this->{$type}[$assocKey]['className'] !== null) { - $class = $this->{$type}[$assocKey]['className']; - } + //if (isset($this->{$type}[$assocKey]['className']) && $this->{$type}[$assocKey]['className'] !== null) { + // $class = $this->{$type}[$assocKey]['className']; + //} foreach($this->__associationKeys[$type] as $key) { if (!isset($this->{$type}[$assocKey][$key]) || $this->{$type}[$assocKey][$key] == null) {