Skip to content

Commit dc55d41

Browse files
committed
add dbgroup to model template only when specified as an option
1 parent 8b1d9fc commit dc55d41

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

system/Commands/Generators/ModelGenerator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ 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+
// Add or remove the DBGroup line based on the presence of the dbgroup option
105+
$addDBGroupLine = is_string($dbGroup) ? true : false;
106+
107+
$table = is_string($table) ? $table : plural(strtolower($baseClass));
108+
$return = is_string($return) ? $return : 'array';
107109

108110
if (! in_array($return, ['array', 'object', 'entity'], true)) {
109111
// @codeCoverageIgnoreStart
@@ -129,6 +131,6 @@ protected function prepare(string $class): string
129131
$return = "'{$return}'";
130132
}
131133

132-
return $this->parseTemplate($class, ['{table}', '{dbGroup}', '{return}'], [$table, $dbGroup, $return]);
134+
return $this->parseTemplate($class, ['{dbGroup}', '{table}', '{return}'], [$dbGroup, $table, $return], compact('addDBGroupLine'));
133135
}
134136
}

system/Commands/Generators/Views/model.tpl.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

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

0 commit comments

Comments
 (0)