Skip to content

Commit

Permalink
Merge pull request #8077 from sammyskills/fix/dbgroup-tpl
Browse files Browse the repository at this point in the history
fix: add dbgroup to model template only when specified as an option
  • Loading branch information
kenjis authored Oct 25, 2023
2 parents 4b43eb0 + 23eb997 commit b56c85c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions system/Commands/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
}
}
2 changes: 2 additions & 0 deletions system/Commands/Generators/Views/model.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

class {class} extends Model
{
<?php if (is_string($dbGroup)): ?>
protected $DBGroup = '{dbGroup}';
<?php endif; ?>
protected $table = '{table}';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
Expand Down
1 change: 0 additions & 1 deletion tests/system/Commands/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit b56c85c

Please sign in to comment.