Skip to content

Commit b389723

Browse files
committed
SqlBuilder: Improved checking of unique table name
1 parent 42227c6 commit b389723

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Database/Table/SqlBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ public function parseJoinsCb(& $joins, $match)
551551
$tableAlias = preg_replace('#^(.*\.)?(.*)$#', '$2', $table);
552552
}
553553

554-
$tableChain .= $keyMatch['del'] . $tableAlias;
554+
$tableChain .= $keyMatch[0];
555555
if (!$isLast || !$this->currentAlias) {
556556
$this->checkUniqueTableName($tableAlias, $tableChain);
557557
}

tests/Database/Table/SqlBuilder.addAlias().phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ test(function() use ($context, $driver) { // test duplicated table names throw e
5151
$joins = [];
5252
$sqlBuilder->parseJoins($joins, $query);
5353
}, Nette\InvalidArgumentException::class, "Table alias 'tag' from chain '.book1:book_tag.tag' is already in use by chain ':book'. Please add/change alias for one of them.");
54+
55+
Assert::exception(function() use ($sqlBuilder) {
56+
$query = 'WHERE :book(translator).id IS NULL AND :book.id IS NULL';
57+
$joins = [];
58+
$sqlBuilder->parseJoins($joins, $query);
59+
}, Nette\InvalidArgumentException::class, "Table alias 'book' from chain ':book' is already in use by chain ':book(translator)'. Please add/change alias for one of them.");
5460
});
5561

5662

0 commit comments

Comments
 (0)