Skip to content
Permalink
Browse files

Correctly generate classnames for plugins as well.

Refs #3791
  • Loading branch information...
markstory committed Jun 26, 2014
1 parent 8588c6d commit 53e85d792e453349e5f791cad2f6b3e1749083fb
Showing with 30 additions and 2 deletions.
  1. +4 −2 src/Console/Command/Task/ModelTask.php
  2. +26 −0 tests/TestCase/Console/Command/Task/ModelTaskTest.php
@@ -226,9 +226,10 @@ public function findBelongsTo($model, array $associations) {
'foreignKey' => $fieldName
];
} elseif ($fieldName === 'parent_id') {
$className = ($this->plugin) ? $this->plugin . '.' . $model->alias() : $model->alias();
$associations['belongsTo'][] = [
'alias' => 'Parent' . $model->alias(),
'className' => $model->alias(),
'className' => $className,
'foreignKey' => $fieldName
];
}
@@ -268,9 +269,10 @@ public function findHasMany($model, array $associations) {
'foreignKey' => $fieldName
];
} elseif ($otherTable == $tableName && $fieldName === 'parent_id') {
$className = ($this->plugin) ? $this->plugin . '.' . $model->alias() : $model->alias();
$assoc = [
'alias' => 'Child' . $model->alias(),
'className' => $model->alias(),
'className' => $className,
'foreignKey' => $fieldName
];
}
@@ -298,6 +298,19 @@ public function testBelongsToGeneration() {
]
];
$this->assertEquals($expected, $result);
$this->Task->plugin = 'Blog';
$result = $this->Task->findBelongsTo($model, array());
$expected = [
'belongsTo' => [
[
'alias' => 'ParentCategoryThreads',
'className' => 'Blog.CategoryThreads',
'foreignKey' => 'parent_id'
],
]
];
$this->assertEquals($expected, $result);
}
/**
@@ -331,6 +344,19 @@ public function testHasManyGeneration() {
]
];
$this->assertEquals($expected, $result);
$this->Task->plugin = 'Blog';
$result = $this->Task->findHasMany($model, array());
$expected = [
'hasMany' => [
[
'alias' => 'ChildCategoryThreads',
'className' => 'Blog.CategoryThreads',
'foreignKey' => 'parent_id'
],
]
];
$this->assertEquals($expected, $result);
}
/**

0 comments on commit 53e85d7

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