diff --git a/system/Commands/Generators/ModelGenerator.php b/system/Commands/Generators/ModelGenerator.php index b4b7ffcda2ca..eb0a1aa9802f 100644 --- a/system/Commands/Generators/ModelGenerator.php +++ b/system/Commands/Generators/ModelGenerator.php @@ -101,9 +101,8 @@ protected function prepare(string $class): string $baseClass = $match[1]; } - $table = is_string($table) ? $table : plural(strtolower($baseClass)); - $dbGroup = is_string($dbGroup) ? $dbGroup : 'default'; - $return = is_string($return) ? $return : 'array'; + $table = is_string($table) ? $table : plural(strtolower($baseClass)); + $return = is_string($return) ? $return : 'array'; if (! in_array($return, ['array', 'object', 'entity'], true)) { // @codeCoverageIgnoreStart @@ -129,6 +128,6 @@ protected function prepare(string $class): string $return = "'{$return}'"; } - return $this->parseTemplate($class, ['{table}', '{dbGroup}', '{return}'], [$table, $dbGroup, $return]); + return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('dbGroup')); } } diff --git a/system/Commands/Generators/Views/model.tpl.php b/system/Commands/Generators/Views/model.tpl.php index ca6d0ec8b954..b9b9c99eb560 100644 --- a/system/Commands/Generators/Views/model.tpl.php +++ b/system/Commands/Generators/Views/model.tpl.php @@ -6,7 +6,9 @@ class {class} extends Model { + protected $DBGroup = '{dbGroup}'; + protected $table = '{table}'; protected $primaryKey = 'id'; protected $useAutoIncrement = true; diff --git a/tests/system/Commands/ModelGeneratorTest.php b/tests/system/Commands/ModelGeneratorTest.php index e6ca050d553b..e1b3c4ae354a 100644 --- a/tests/system/Commands/ModelGeneratorTest.php +++ b/tests/system/Commands/ModelGeneratorTest.php @@ -52,7 +52,6 @@ public function testGenerateModel(): void $this->assertFileExists($file); $this->assertStringContainsString('extends Model', $this->getFileContent($file)); $this->assertStringContainsString('protected $table = \'users\';', $this->getFileContent($file)); - $this->assertStringContainsString('protected $DBGroup = \'default\';', $this->getFileContent($file)); $this->assertStringContainsString('protected $returnType = \'array\';', $this->getFileContent($file)); }