Skip to content

Commit

Permalink
Adding App::uses() call to model baking.
Browse files Browse the repository at this point in the history
Models should always include their parent classes to be safe.
Bake should reflect the best practice.
Refs #1971
  • Loading branch information
markstory committed Sep 10, 2011
1 parent 1743eaa commit 7c08c96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/Cake/Console/Command/Task/ModelTask.php
Expand Up @@ -743,7 +743,10 @@ public function bake($name, $data = array()) {
$data = array_merge($defaults, $data);

$this->Template->set($data);
$this->Template->set('plugin', $this->plugin);
$this->Template->set(array(
'plugin' => $this->plugin,
'pluginPath' => empty($this->plugin) ? '' : $this->plugin . '.'
));
$out = $this->Template->generate('classes', 'model');

$path = $this->getPath();
Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Console/Templates/default/classes/model.ctp
Expand Up @@ -19,7 +19,9 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

echo "<?php\n"; ?>
echo "<?php\n";
echo "App::uses('{$plugin}AppModel', '{$pluginPath}Model');\n";
?>
/**
* <?php echo $name ?> Model
*
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -754,7 +754,8 @@ public function testBakeWithPlugin() {
$this->Task->expects($this->once())->method('createFile')
->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/BakeArticle extends ControllerTestAppModel/'));

$this->Task->bake('BakeArticle', array(), array());
$result = $this->Task->bake('BakeArticle', array(), array());
$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);

$this->assertEqual(count(ClassRegistry::keys()), 0);
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
Expand Down

0 comments on commit 7c08c96

Please sign in to comment.