Skip to content

Commit

Permalink
Correctly generate classnames for plugins as well.
Browse files Browse the repository at this point in the history
Refs #3791
  • Loading branch information
markstory committed Jun 26, 2014
1 parent 8588c6d commit 53e85d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -226,9 +226,10 @@ public function findBelongsTo($model, array $associations) {
'foreignKey' => $fieldName 'foreignKey' => $fieldName
]; ];
} elseif ($fieldName === 'parent_id') { } elseif ($fieldName === 'parent_id') {
$className = ($this->plugin) ? $this->plugin . '.' . $model->alias() : $model->alias();
$associations['belongsTo'][] = [ $associations['belongsTo'][] = [
'alias' => 'Parent' . $model->alias(), 'alias' => 'Parent' . $model->alias(),
'className' => $model->alias(), 'className' => $className,
'foreignKey' => $fieldName 'foreignKey' => $fieldName
]; ];
} }
Expand Down Expand Up @@ -268,9 +269,10 @@ public function findHasMany($model, array $associations) {
'foreignKey' => $fieldName 'foreignKey' => $fieldName
]; ];
} elseif ($otherTable == $tableName && $fieldName === 'parent_id') { } elseif ($otherTable == $tableName && $fieldName === 'parent_id') {
$className = ($this->plugin) ? $this->plugin . '.' . $model->alias() : $model->alias();
$assoc = [ $assoc = [
'alias' => 'Child' . $model->alias(), 'alias' => 'Child' . $model->alias(),
'className' => $model->alias(), 'className' => $className,
'foreignKey' => $fieldName 'foreignKey' => $fieldName
]; ];
} }
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -298,6 +298,19 @@ public function testBelongsToGeneration() {
] ]
]; ];
$this->assertEquals($expected, $result); $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);
} }


/** /**
Expand Down Expand Up @@ -331,6 +344,19 @@ public function testHasManyGeneration() {
] ]
]; ];
$this->assertEquals($expected, $result); $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);
} }


/** /**
Expand Down

0 comments on commit 53e85d7

Please sign in to comment.