Skip to content

Commit

Permalink
iRemoving table key from belongsTo assocs in bake
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 18, 2014
1 parent 761da8b commit 1ac09f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -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
];
}
}
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 4 additions & 8 deletions tests/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -243,8 +243,7 @@ public function testGetAssociations() {
'belongsTo' => [
[
'alias' => 'BakeUsers',
'foreignKey' => 'bake_user_id',
'table' => 'bake_users'
'foreignKey' => 'bake_user_id'
],
],
'hasMany' => [
Expand Down Expand Up @@ -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'
],
]
];
Expand All @@ -295,8 +292,7 @@ public function testBelongsToGeneration() {
'belongsTo' => [
[
'alias' => 'ParentCategoryThreads',
'foreignKey' => 'parent_id',
'table' => 'category_threads'
'foreignKey' => 'parent_id'
],
]
];
Expand Down

0 comments on commit 1ac09f1

Please sign in to comment.