mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
"Removing var $useTable; from generated model when tables follow conventions
Fixed issue with model tests and fixtures not being created properly when Model name does not match table name" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6331 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e3f23df3d2
commit
d6bcff4797
1 changed files with 16 additions and 8 deletions
|
@ -181,7 +181,7 @@ class ModelTask extends Shell {
|
||||||
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
||||||
if ($this->bake($currentModelName, $associations, $validate, $primaryKey, $useTable, $useDbConfig)) {
|
if ($this->bake($currentModelName, $associations, $validate, $primaryKey, $useTable, $useDbConfig)) {
|
||||||
if ($this->_checkUnitTest()) {
|
if ($this->_checkUnitTest()) {
|
||||||
$this->bakeTest($currentModelName);
|
$this->bakeTest($currentModelName, $useTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -488,8 +488,12 @@ class ModelTask extends Shell {
|
||||||
$out .= "\tvar \$useDbConfig = '$useDbConfig';\n";
|
$out .= "\tvar \$useDbConfig = '$useDbConfig';\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($useTable === Inflector::tableize($name)) {
|
if (($useTable && $useTable !== Inflector::tableize($name)) || $useTable === false) {
|
||||||
$out .= "\tvar \$useTable = '$useTable';\n";
|
$table = "'$useTable'";
|
||||||
|
if (!$useTable) {
|
||||||
|
$table = 'false';
|
||||||
|
}
|
||||||
|
$out .= "\tvar \$useTable = $table;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($primaryKey !== 'id') {
|
if ($primaryKey !== 'id') {
|
||||||
|
@ -626,8 +630,8 @@ class ModelTask extends Shell {
|
||||||
* @param string $className Model class name
|
* @param string $className Model class name
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function bakeTest($className) {
|
function bakeTest($className, $useTable = null) {
|
||||||
$results = $this->fixture($className);
|
$results = $this->fixture($className, $useTable);
|
||||||
|
|
||||||
if ($results) {
|
if ($results) {
|
||||||
$fixture = Inflector::underscore($className);
|
$fixture = Inflector::underscore($className);
|
||||||
|
@ -732,18 +736,23 @@ class ModelTask extends Shell {
|
||||||
* Builds the tests fixtures for the model and create the file
|
* Builds the tests fixtures for the model and create the file
|
||||||
*
|
*
|
||||||
* @param string $model the name of the model
|
* @param string $model the name of the model
|
||||||
|
* @param string $useTable table name
|
||||||
* @return array $records, used in ModelTask::bakeTest() to create $expected
|
* @return array $records, used in ModelTask::bakeTest() to create $expected
|
||||||
* @todo move this to a task
|
* @todo move this to a task
|
||||||
*/
|
*/
|
||||||
function fixture($model) {
|
function fixture($model, $useTable = null) {
|
||||||
if (!class_exists('CakeSchema')) {
|
if (!class_exists('CakeSchema')) {
|
||||||
App::import('Model', 'Schema');
|
App::import('Model', 'Schema');
|
||||||
}
|
}
|
||||||
|
if (!$useTable) {
|
||||||
|
$useTable = Inflector::tableize($model);
|
||||||
|
}
|
||||||
$schema = new CakeSchema();
|
$schema = new CakeSchema();
|
||||||
$data = $schema->read(array('models' => false));
|
$data = $schema->read(array('models' => false));
|
||||||
$tables[$model] = $data['tables']['missing'][Inflector::tableize($model)];
|
$tables[$model] = $data['tables']['missing'][$useTable];
|
||||||
$out = "\nclass {$model}Fixture extends CakeTestFixture {\n";
|
$out = "\nclass {$model}Fixture extends CakeTestFixture {\n";
|
||||||
$out .= "\tvar \$name = '$model';\n";
|
$out .= "\tvar \$name = '$model';\n";
|
||||||
|
|
||||||
foreach ($tables as $table => $fields) {
|
foreach ($tables as $table => $fields) {
|
||||||
if (!is_numeric($table) && $table !== 'missing') {
|
if (!is_numeric($table) && $table !== 'missing') {
|
||||||
$out .= "\tvar \$fields = array(\n";
|
$out .= "\tvar \$fields = array(\n";
|
||||||
|
@ -788,7 +797,6 @@ class ModelTask extends Shell {
|
||||||
feugiat lacinia mauris sed, lacinia et felis.\'';
|
feugiat lacinia mauris sed, lacinia et felis.\'';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$records[] = "\t\t\t'$field' => $insert";
|
$records[] = "\t\t\t'$field' => $insert";
|
||||||
unset($value['type']);
|
unset($value['type']);
|
||||||
$col .= join(', ', $schema->__values($value));
|
$col .= join(', ', $schema->__values($value));
|
||||||
|
|
Loading…
Add table
Reference in a new issue