mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-03 01:52:40 +00:00
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:
parent
4f110a0ef9
commit
fc54b0f31a
3 changed files with 20 additions and 16 deletions
|
@ -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.
|
* after the redirect.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
@ -630,7 +630,7 @@ class Controller extends Object {
|
||||||
$model = $this->modelClass;
|
$model = $this->modelClass;
|
||||||
$modelKey = $this->modelKey;
|
$modelKey = $this->modelKey;
|
||||||
$table = $this->{$model}->table;
|
$table = $this->{$model}->table;
|
||||||
$association = array_search($table, $this->{$model}->alias);
|
//$association = array_search($table, $this->{$model}->alias);
|
||||||
$objRegistryModel =& ClassRegistry::getObject($modelKey);
|
$objRegistryModel =& ClassRegistry::getObject($modelKey);
|
||||||
|
|
||||||
foreach($objRegistryModel->_tableInfo as $tables) {
|
foreach($objRegistryModel->_tableInfo as $tables) {
|
||||||
|
@ -644,7 +644,7 @@ class Controller extends Object {
|
||||||
}
|
}
|
||||||
$fkNames = $this->{$model}->keyToTable[$tabl['name']];
|
$fkNames = $this->{$model}->keyToTable[$tabl['name']];
|
||||||
$fieldNames[$tabl['name']]['table'] = $fkNames[0];
|
$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']]['prompt'] = Inflector::humanize($niceName);
|
||||||
$fieldNames[$tabl['name']]['model'] = $fkNames[1];
|
$fieldNames[$tabl['name']]['model'] = $fkNames[1];
|
||||||
$fieldNames[$tabl['name']]['modelKey'] = $this->{$model}->tableToModel[$fieldNames[$tabl['name']]['table']];
|
$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 {
|
} else {
|
||||||
$fieldNames[$tabl['name']]['type'] = 'input';
|
$fieldNames[$tabl['name']]['type'] = 'input';
|
||||||
|
|
|
@ -526,7 +526,7 @@ class DboSource extends DataSource {
|
||||||
foreach($model->__associations as $type) {
|
foreach($model->__associations as $type) {
|
||||||
foreach($model->{$type} as $assoc => $assocData) {
|
foreach($model->{$type} as $assoc => $assocData) {
|
||||||
if ($model->recursive > -1) {
|
if ($model->recursive > -1) {
|
||||||
$linkModel =& $model->{$assocData['className']};
|
$linkModel =& $model->{$assoc};
|
||||||
|
|
||||||
if ($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
|
if ($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
|
||||||
if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null)) {
|
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->__associations as $type) {
|
||||||
foreach($model->{$type} as $assoc => $assocData) {
|
foreach($model->{$type} as $assoc => $assocData) {
|
||||||
$db = null;
|
$db = null;
|
||||||
$linkModel =& $model->{$assocData['className']};
|
$linkModel =& $model->{$assoc};
|
||||||
|
|
||||||
if (!in_array($type . '/' . $assoc, $linkedModels)) {
|
if (!in_array($type . '/' . $assoc, $linkedModels)) {
|
||||||
if ($model->useDbConfig == $linkModel->useDbConfig) {
|
if ($model->useDbConfig == $linkModel->useDbConfig) {
|
||||||
|
|
|
@ -554,21 +554,25 @@ class Model extends Overloadable {
|
||||||
|
|
||||||
if (ClassRegistry::isKeySet($colKey)) {
|
if (ClassRegistry::isKeySet($colKey)) {
|
||||||
if (!PHP5) {
|
if (!PHP5) {
|
||||||
$this->{$className} =& ClassRegistry::getObject($colKey);
|
$this->{$assoc} =& ClassRegistry::getObject($colKey);
|
||||||
|
$this->{$className} =& $this->{$assoc};
|
||||||
} else {
|
} else {
|
||||||
$this->{$className} = ClassRegistry::getObject($colKey);
|
$this->{$assoc} = ClassRegistry::getObject($colKey);
|
||||||
|
$this->{$className} = $this->{$assoc};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!PHP5) {
|
if (!PHP5) {
|
||||||
$this->{$className} =& new $className($id, $table, $ds);
|
$this->{$assoc} =& new $className($id, $table, $ds);
|
||||||
|
$this->{$className} =& $this->{$assoc};
|
||||||
} else {
|
} 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->alias[$assoc] = $this->{$assoc}->table;
|
||||||
$this->tableToModel[$this->{$className}->table] = $className;
|
$this->tableToModel[$this->{$assoc}->table] = $assoc;
|
||||||
$this->modelToTable[$className] = $this->{$className}->table;
|
$this->modelToTable[$assoc] = $this->{$assoc}->table;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Build array-based association from string.
|
* Build array-based association from string.
|
||||||
|
@ -580,9 +584,9 @@ class Model extends Overloadable {
|
||||||
foreach($this->{$type} as $assocKey => $assocData) {
|
foreach($this->{$type} as $assocKey => $assocData) {
|
||||||
$class = $assocKey;
|
$class = $assocKey;
|
||||||
|
|
||||||
if (isset($this->{$type}[$assocKey]['className']) && $this->{$type}[$assocKey]['className'] !== null) {
|
//if (isset($this->{$type}[$assocKey]['className']) && $this->{$type}[$assocKey]['className'] !== null) {
|
||||||
$class = $this->{$type}[$assocKey]['className'];
|
// $class = $this->{$type}[$assocKey]['className'];
|
||||||
}
|
//}
|
||||||
|
|
||||||
foreach($this->__associationKeys[$type] as $key) {
|
foreach($this->__associationKeys[$type] as $key) {
|
||||||
if (!isset($this->{$type}[$assocKey][$key]) || $this->{$type}[$assocKey][$key] == null) {
|
if (!isset($this->{$type}[$assocKey][$key]) || $this->{$type}[$assocKey][$key] == null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue