Skip to content

Commit

Permalink
Fix #133: Allow some special chars in table name (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadasjad authored Sep 23, 2024
1 parent cf2f56d commit cce28a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Generator/ActiveRecord/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
private readonly string $namespace = 'App\\Model',
#[Required]
#[Regex(
pattern: '/^[a-z_][a-z0-9_]*$/i',
pattern: '/^[\w-]+\.?[\w-]*$/i',
message: 'Invalid table name'
)]
#[TableExistsRule]
Expand Down
7 changes: 6 additions & 1 deletion src/Validator/TableExistsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public function validate(mixed $value, object $rule, ValidationContext $context)

$result = new Result();

$tableSchema = $this->connection->getTableSchema($value);
try {
$tableSchema = $this->connection->getTableSchema($value);
} catch (\Yiisoft\Db\Exception\Exception $e) {
$result->addError($e->getMessage());
return $result;
}

if ($tableSchema === null) {
$result->addError(sprintf('Table "%s" does not exist.', $value));
Expand Down

0 comments on commit cce28a9

Please # to comment.