Skip to content
Permalink
Browse files

Fixing issue where baking a model non-interactively would omit hasMan…

…y associations. Tests added.
  • Loading branch information...
markstory committed Feb 21, 2010
1 parent 8ce9560 commit 8615274e7f263803219aaf7540db71ec6dac142d
Showing with 21 additions and 1 deletion.
  1. +5 −1 cake/console/libs/tasks/model.php
  2. +16 −0 cake/tests/cases/console/libs/tasks/model.test.php
@@ -465,6 +465,10 @@ function doAssociations(&$model) {
return false;
}
if (empty($this->_tables)) {
$this->_tables = $this->getAllTables();
}
$associations = array(
'belongsTo' => array(), 'hasMany' => array(), 'hasOne'=> array(), 'hasAndBelongsToMany' => array()
);
@@ -532,7 +536,7 @@ function findHasOneAndMany(&$model, $associations) {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema();
$modelFieldsTemp = $tempOtherModel->schema(true);
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
$possibleJoinTable = preg_match($pattern , $otherTable);
@@ -707,6 +707,22 @@ function testExecuteWithNamedModel() {
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
}
/**
* test that execute with a model name picks up hasMany associations.
*
* @return void
* @access public
*/
function testExecuteWithNamedModelHasManyCreated() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('article');
$filename = '/my/path/article.php';
$this->Task->setReturnValue('_checkUnitTest', 1);
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation("/'Comment' \=\> array\(/")));
$this->Task->execute();
}
/**
* test that execute runs all() when args[0] = all
*

0 comments on commit 8615274

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