Skip to content
Permalink
Browse files

Add missing className option to generated associations.

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 8588c6de3c31dd71b0b8e4a32b721ff12bd5f814
Showing with 4 additions and 0 deletions.
  1. +2 −0 src/Console/Command/Task/ModelTask.php
  2. +2 −0 tests/TestCase/Console/Command/Task/ModelTaskTest.php
@@ -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
];
}
@@ -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
];
}
@@ -292,6 +292,7 @@ public function testBelongsToGeneration() {
'belongsTo' => [
[
'alias' => 'ParentCategoryThreads',
'className' => 'CategoryThreads',
'foreignKey' => 'parent_id'
],
]
@@ -324,6 +325,7 @@ public function testHasManyGeneration() {
'hasMany' => [
[
'alias' => 'ChildCategoryThreads',
'className' => 'CategoryThreads',
'foreignKey' => 'parent_id',
],
]

0 comments on commit 8588c6d

Please sign in to comment.
You can’t perform that action at this time.