mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-07 12:02:41 +00:00
Fixing issues with models using default inflected tables instead of their actual tables when detecting associations. Fixes #315
This commit is contained in:
parent
ddb9f8924c
commit
89558dc4af
1 changed files with 7 additions and 4 deletions
|
@ -130,8 +130,11 @@ class ModelTask extends Shell {
|
|||
* @param string $className Name of class you want model to be.
|
||||
* @return object Model instance
|
||||
*/
|
||||
function &_getModelObject($className) {
|
||||
$object = new Model(array('name' => $className, 'ds' => $this->connection));
|
||||
function &_getModelObject($className, $table = null) {
|
||||
if (!$table) {
|
||||
$table = Inflector::tableize($className);
|
||||
}
|
||||
$object =& new Model(array('name' => $className, 'table' => $table, 'ds' => $this->connection));
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
@ -517,7 +520,7 @@ class ModelTask extends Shell {
|
|||
function findHasOneAndMany(&$model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->__tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable));
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
$modelFieldsTemp = $tempOtherModel->schema();
|
||||
|
||||
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
|
||||
|
@ -560,7 +563,7 @@ class ModelTask extends Shell {
|
|||
function findHasAndBelongsToMany(&$model, $associations) {
|
||||
$foreignKey = $this->_modelKey($model->name);
|
||||
foreach ($this->__tables as $otherTable) {
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable));
|
||||
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
|
||||
$modelFieldsTemp = $tempOtherModel->schema();
|
||||
|
||||
$offset = strpos($otherTable, $model->table . '_');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue