Skip to content

Commit b56c85c

Browse files
authored
Merge pull request #8077 from sammyskills/fix/dbgroup-tpl
fix: add dbgroup to model template only when specified as an option
2 parents 4b43eb0 + 23eb997 commit b56c85c

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Diff for: system/Commands/Generators/ModelGenerator.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ protected function prepare(string $class): string
101101
$baseClass = $match[1];
102102
}
103103

104-
$table = is_string($table) ? $table : plural(strtolower($baseClass));
105-
$dbGroup = is_string($dbGroup) ? $dbGroup : 'default';
106-
$return = is_string($return) ? $return : 'array';
104+
$table = is_string($table) ? $table : plural(strtolower($baseClass));
105+
$return = is_string($return) ? $return : 'array';
107106

108107
if (! in_array($return, ['array', 'object', 'entity'], true)) {
109108
// @codeCoverageIgnoreStart
@@ -129,6 +128,6 @@ protected function prepare(string $class): string
129128
$return = "'{$return}'";
130129
}
131130

132-
return $this->parseTemplate($class, ['{table}', '{dbGroup}', '{return}'], [$table, $dbGroup, $return]);
131+
return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('dbGroup'));
133132
}
134133
}

Diff for: system/Commands/Generators/Views/model.tpl.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
class {class} extends Model
88
{
9+
<?php if (is_string($dbGroup)): ?>
910
protected $DBGroup = '{dbGroup}';
11+
<?php endif; ?>
1012
protected $table = '{table}';
1113
protected $primaryKey = 'id';
1214
protected $useAutoIncrement = true;

Diff for: tests/system/Commands/ModelGeneratorTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function testGenerateModel(): void
5252
$this->assertFileExists($file);
5353
$this->assertStringContainsString('extends Model', $this->getFileContent($file));
5454
$this->assertStringContainsString('protected $table = \'users\';', $this->getFileContent($file));
55-
$this->assertStringContainsString('protected $DBGroup = \'default\';', $this->getFileContent($file));
5655
$this->assertStringContainsString('protected $returnType = \'array\';', $this->getFileContent($file));
5756
}
5857

0 commit comments

Comments
 (0)