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
This commit is contained in:
phpnut 2006-09-14 21:59:51 +00:00
parent 4f110a0ef9
commit fc54b0f31a
3 changed files with 20 additions and 16 deletions

View file

@ -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';

View file

@ -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) {

View file

@ -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) {