Skip to content

Commit

Permalink
Fix schema specification support in WHERE clauses (#322)
Browse files Browse the repository at this point in the history
* Fix bug with WHERE from other db
* Change name
* Change name back
  • Loading branch information
gillsonkell committed Jan 3, 2022
1 parent 1a0e9ad commit 787c8fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Queries/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ private function createUndefinedJoins($statement)
// don't rewrite table from other databases
foreach ($this->joins as $join) {
if (strpos($join, '.') !== false && strpos($statement, $join) === 0) {
// rebuild the where statement
if ($separator !== null) {
$statement = [$separator, $statement];
}

return $statement;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Queries/CommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ public function testClauseWithRefBeforeJoin()

public function testFromOtherDB()
{
$queryPrint = $this->fluent->from('db2.user')->order('db2.user.name')->getQuery(false);
$queryPrint = $this->fluent->from('db2.user')->where('db2.user.name', 'name')->order('db2.user.name')->getQuery(false);

self::assertEquals('SELECT db2.user.* FROM db2.user ORDER BY db2.user.name', $queryPrint);
self::assertEquals('SELECT db2.user.* FROM db2.user WHERE db2.user.name = ? ORDER BY db2.user.name', $queryPrint);
}

public function testJoinTableWithUsing()
Expand Down

0 comments on commit 787c8fa

Please sign in to comment.