Skip to content

Commit

Permalink
set foreign table query table if not already set
Browse files Browse the repository at this point in the history
  • Loading branch information
danomatic committed Apr 16, 2017
1 parent c6fddd7 commit 4ecbec8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ protected function update() {
/**
* @param string $foreign_table
* @param string $foreign_column
* @param string $local_column
* @param Query $q
* @return Query
*/
Expand All @@ -1459,12 +1460,16 @@ protected function getForeignObjectsQuery($foreign_table, $foreign_column, $loca
$column = "$foreign_table.$foreign_column";
if ($q) {
$q = clone $q;
if (!$q->getTable()) {
$q->setTable($foreign_table);
}

$alias = $q->getAlias();
if ($alias && $foreign_table == $q->getTable()) {
$column = "$alias.$foreign_column";
}
} else {
$q = new Query;
$q = new Query($foreign_table);
}
$q->add($column, $value);
return $q;
Expand Down

0 comments on commit 4ecbec8

Please sign in to comment.