Skip to content

Commit

Permalink
Add missing className option to generated associations.
Browse files Browse the repository at this point in the history
Child/Parent associations need to specify the className key or the
incorrect classname will be inferred at runtime causing errors.

We're using the alias as a proxy for classname, as we can't use the
actual classname as bake may be using a base class replacement.

Refs #3791
  • Loading branch information
markstory committed Jun 26, 2014
1 parent 6105948 commit 8588c6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -228,6 +228,7 @@ public function findBelongsTo($model, array $associations) {
} elseif ($fieldName === 'parent_id') {
$associations['belongsTo'][] = [
'alias' => 'Parent' . $model->alias(),
'className' => $model->alias(),
'foreignKey' => $fieldName
];
}
Expand Down Expand Up @@ -269,6 +270,7 @@ public function findHasMany($model, array $associations) {
} elseif ($otherTable == $tableName && $fieldName === 'parent_id') {
$assoc = [
'alias' => 'Child' . $model->alias(),
'className' => $model->alias(),
'foreignKey' => $fieldName
];
}
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -292,6 +292,7 @@ public function testBelongsToGeneration() {
'belongsTo' => [
[
'alias' => 'ParentCategoryThreads',
'className' => 'CategoryThreads',
'foreignKey' => 'parent_id'
],
]
Expand Down Expand Up @@ -324,6 +325,7 @@ public function testHasManyGeneration() {
'hasMany' => [
[
'alias' => 'ChildCategoryThreads',
'className' => 'CategoryThreads',
'foreignKey' => 'parent_id',
],
]
Expand Down

0 comments on commit 8588c6d

Please sign in to comment.