Commit a269fcdb authored by zYne's avatar zYne

Custom join condition model rewritte, full support for ON and WITH keywords

parent 34711038
......@@ -674,7 +674,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if (isset($this->_pendingJoinConditions[$k])) {
$parser = new Doctrine_Query_JoinCondition($this);
$part .= ' AND ' . $parser->parse($this->_pendingJoinConditions[$k]);
if (strpos($part, ' ON ') !== false) {
$part .= ' AND ';
} else {
$part .= ' ON ';
}
$part .= $parser->parse($this->_pendingJoinConditions[$k]);
unset($this->_pendingJoinConditions[$k]);
}
......@@ -1113,6 +1119,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
return $this;
}
public function load($path, $loadFields = true)
{
// parse custom join conditions
......@@ -1120,10 +1127,19 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$joinCondition = '';
if (count($e) > 1) {
$joinCondition = $e[1];
$overrideJoin = true;
$path = $e[0];
} else {
$e = explode(' WITH ', $path);
if (count($e) > 1) {
$joinCondition = $e[1];
$path = $e[0];
}
$overrideJoin = false;
}
$tmp = explode(' ', $path);
$componentAlias = $originalAlias = (count($tmp) > 1) ? end($tmp) : null;
......@@ -1207,23 +1223,36 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$assocAlias = $this->getTableAlias($assocPath, $asf->getTableName());
$queryPart = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $localAlias . '.'
. $table->getIdentifier() . ' = '
$queryPart = $join . $assocTableName . ' ' . $assocAlias;
$queryPart .= ' ON ' . $localAlias
. '.'
. $table->getIdentifier()
. ' = '
. $assocAlias . '.' . $relation->getLocal();
if ($relation->isEqual()) {
$queryPart .= ' OR ' . $localAlias . '.'
. $table->getIdentifier() . ' = '
// equal nest relation needs additional condition
$queryPart .= ' OR ' . $localAlias
. '.'
. $table->getIdentifier()
. ' = '
. $assocAlias . '.' . $relation->getForeign();
}
$this->parts['from'][] = $queryPart;
$queryPart = $join . $foreignSql . ' ON ';
$queryPart = $join . $foreignSql;
if ( ! $overrideJoin) {
$queryPart .= ' ON ';
if ($relation->isEqual()) {
$queryPart .= '(';
}
$queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getTable()->getIdentifier())
. ' = '
. $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getForeign());
......@@ -1238,14 +1267,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
. ' != '
. $this->_conn->quoteIdentifier($localAlias . '.' . $table->getIdentifier());
}
}
} else {
$queryPart = $join . $foreignSql
. ' ON '
$queryPart = $join . $foreignSql;
if ( ! $overrideJoin) {
$queryPart .= ' ON '
. $this->_conn->quoteIdentifier($localAlias . '.' . $relation->getLocal())
. ' = '
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getForeign());
}
}
$this->parts['from'][$componentAlias] = $queryPart;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment