From 1ac09f1b1c3c654cb43432cb5a15a6ab570f2899 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 19 Jun 2014 00:32:56 +0200 Subject: [PATCH] iRemoving table key from belongsTo assocs in bake --- src/Console/Command/Task/ModelTask.php | 8 +++----- .../TestCase/Console/Command/Task/ModelTaskTest.php | 12 ++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Console/Command/Task/ModelTask.php b/src/Console/Command/Task/ModelTask.php index 3434824230c..8a8d375d0fb 100644 --- a/src/Console/Command/Task/ModelTask.php +++ b/src/Console/Command/Task/ModelTask.php @@ -225,14 +225,12 @@ public function findBelongsTo($model, array $associations) { $tmpModelName = $this->_modelNameFromKey($fieldName); $associations['belongsTo'][] = [ 'alias' => $tmpModelName, - 'foreignKey' => $fieldName, - 'table' => Inflector::underscore($tmpModelName) + 'foreignKey' => $fieldName ]; } elseif ($fieldName === 'parent_id') { $associations['belongsTo'][] = [ 'alias' => 'Parent' . $model->alias(), - 'foreignKey' => $fieldName, - 'table' => $model->table() + 'foreignKey' => $fieldName ]; } } @@ -530,7 +528,7 @@ public function getCounterCache($model) { $counterCache = []; foreach ($belongsTo['belongsTo'] as $otherTable) { $otherAlias = $otherTable['alias']; - $otherModel = $this->getTableObject($this->_modelName($otherAlias), $otherTable['table']); + $otherModel = $this->getTableObject($this->_modelName($otherAlias), Inflector::underscore($otherAlias)); try { $otherSchema = $otherModel->schema(); diff --git a/tests/TestCase/Console/Command/Task/ModelTaskTest.php b/tests/TestCase/Console/Command/Task/ModelTaskTest.php index 8c412804fa9..171dc9dec6d 100644 --- a/tests/TestCase/Console/Command/Task/ModelTaskTest.php +++ b/tests/TestCase/Console/Command/Task/ModelTaskTest.php @@ -243,8 +243,7 @@ public function testGetAssociations() { 'belongsTo' => [ [ 'alias' => 'BakeUsers', - 'foreignKey' => 'bake_user_id', - 'table' => 'bake_users' + 'foreignKey' => 'bake_user_id' ], ], 'hasMany' => [ @@ -277,13 +276,11 @@ public function testBelongsToGeneration() { 'belongsTo' => [ [ 'alias' => 'BakeArticles', - 'foreignKey' => 'bake_article_id', - 'table' => 'bake_articles' + 'foreignKey' => 'bake_article_id' ], [ 'alias' => 'BakeUsers', - 'foreignKey' => 'bake_user_id', - 'table' => 'bake_users' + 'foreignKey' => 'bake_user_id' ], ] ]; @@ -295,8 +292,7 @@ public function testBelongsToGeneration() { 'belongsTo' => [ [ 'alias' => 'ParentCategoryThreads', - 'foreignKey' => 'parent_id', - 'table' => 'category_threads' + 'foreignKey' => 'parent_id' ], ] ];