1
0
mirror of synced 2025-03-21 23:43:53 +03:00

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

This commit is contained in:
zYne 2007-07-31 19:33:58 +00:00
parent 3471103892
commit a269fcdb18

View File

@ -674,7 +674,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if (isset($this->_pendingJoinConditions[$k])) { if (isset($this->_pendingJoinConditions[$k])) {
$parser = new Doctrine_Query_JoinCondition($this); $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]); unset($this->_pendingJoinConditions[$k]);
} }
@ -1113,6 +1119,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
return $this; return $this;
} }
public function load($path, $loadFields = true) public function load($path, $loadFields = true)
{ {
// parse custom join conditions // parse custom join conditions
@ -1122,7 +1129,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if (count($e) > 1) { if (count($e) > 1) {
$joinCondition = $e[1]; $joinCondition = $e[1];
$overrideJoin = true;
$path = $e[0]; $path = $e[0];
} else {
$e = explode(' WITH ', $path);
if (count($e) > 1) {
$joinCondition = $e[1];
$path = $e[0];
}
$overrideJoin = false;
} }
$tmp = explode(' ', $path); $tmp = explode(' ', $path);
@ -1207,23 +1223,36 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$assocAlias = $this->getTableAlias($assocPath, $asf->getTableName()); $assocAlias = $this->getTableAlias($assocPath, $asf->getTableName());
$queryPart = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $localAlias . '.' $queryPart = $join . $assocTableName . ' ' . $assocAlias;
. $table->getIdentifier() . ' = '
$queryPart .= ' ON ' . $localAlias
. '.'
. $table->getIdentifier()
. ' = '
. $assocAlias . '.' . $relation->getLocal(); . $assocAlias . '.' . $relation->getLocal();
if ($relation->isEqual()) { if ($relation->isEqual()) {
$queryPart .= ' OR ' . $localAlias . '.' // equal nest relation needs additional condition
. $table->getIdentifier() . ' = ' $queryPart .= ' OR ' . $localAlias
. '.'
. $table->getIdentifier()
. ' = '
. $assocAlias . '.' . $relation->getForeign(); . $assocAlias . '.' . $relation->getForeign();
} }
$this->parts['from'][] = $queryPart; $this->parts['from'][] = $queryPart;
$queryPart = $join . $foreignSql . ' ON '; $queryPart = $join . $foreignSql;
if ( ! $overrideJoin) {
$queryPart .= ' ON ';
if ($relation->isEqual()) { if ($relation->isEqual()) {
$queryPart .= '('; $queryPart .= '(';
} }
$queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getTable()->getIdentifier()) $queryPart .= $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getTable()->getIdentifier())
. ' = ' . ' = '
. $this->_conn->quoteIdentifier($assocAlias . '.' . $relation->getForeign()); . $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()); . $this->_conn->quoteIdentifier($localAlias . '.' . $table->getIdentifier());
} }
}
} else { } else {
$queryPart = $join . $foreignSql $queryPart = $join . $foreignSql;
. ' ON '
if ( ! $overrideJoin) {
$queryPart .= ' ON '
. $this->_conn->quoteIdentifier($localAlias . '.' . $relation->getLocal()) . $this->_conn->quoteIdentifier($localAlias . '.' . $relation->getLocal())
. ' = ' . ' = '
. $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getForeign()); . $this->_conn->quoteIdentifier($foreignAlias . '.' . $relation->getForeign());
}
} }
$this->parts['from'][$componentAlias] = $queryPart; $this->parts['from'][$componentAlias] = $queryPart;