1
0
mirror of synced 2024-12-15 07:36:03 +03:00
This commit is contained in:
zYne 2007-05-11 21:33:31 +00:00
parent 6a2012b4cf
commit 42e9c4b2bb
2 changed files with 96 additions and 56 deletions

View File

@ -190,7 +190,14 @@ class Doctrine_Hydrate2
{ {
return false; return false;
} }
public function getQueryPart($part)
{
if ( ! isset($this->parts[$part])) {
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $part);
}
return $this->parts[$part];
}
/** /**
* remove * remove
* *

View File

@ -1030,6 +1030,7 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
return $tableName; return $tableName;
} }
} }
public function load($path, $loadFields = true) public function load($path, $loadFields = true)
{ {
// parse custom join conditions // parse custom join conditions
@ -1045,19 +1046,102 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
$tmp = explode(' ', $path); $tmp = explode(' ', $path);
$componentAlias = (count($tmp) > 1) ? end($tmp) : false; $componentAlias = (count($tmp) > 1) ? end($tmp) : false;
$e = preg_split("/[.:]/", $tmp[0], -1); $e = preg_split("/[.:]/", $tmp[0], -1);
foreach ($e as $key => $part) { if (isset($this->_aliasMap[$e[0]])) {
$table = $this->_aliasMap[$e[0]]['table'];
if ($key === 0) { $parent = array_shift($e);
}
foreach ($e as $key => $name) {
if ( ! isset($table)) {
// process the root of the path // process the root of the path
$table = $this->loadRoot($name, $componentAlias);
} else {
$relation = $table->getRelation($name);
$this->_aliasMap[$componentAlias] = array('parent' => $parent,
'relation' => $relation);
if( ! $fk->isOneToOne()) {
$this->needsSubquery = true;
}
$map = $fk->getTable()->inheritanceMap;
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $tname2;
}
if ($fk instanceof Doctrine_Relation_Association) {
$asf = $fk->getAssociationFactory();
$assocTableName = $asf->getTableName();
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $assocTableName;
}
$assocPath = $prevPath . '.' . $asf->getComponentName();
if (isset($this->tableAliases[$assocPath])) {
$assocAlias = $this->tableAliases[$assocPath];
} else {
$assocAlias = $this->aliasHandler->generateShortAlias($assocTableName);
}
$this->parts['from'] = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $tname . '.'
. $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'] .= ' OR ' . $tname . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign();
}
$this->parts['from'] = $join . $aliasString . ' ON ' . $tname2 . '.'
. $fk->getTable()->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign()
. $joinCondition;
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'] .= ' OR ' . $tname2 . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
}
} else { } else {
$this->parts['join'] = $join . $aliasString
. ' ON ' . $tname . '.'
. $fk->getLocal() . ' = ' . $tname2 . '.' . $fk->getForeign()
. $joinCondition;
}
} }
} }
} }
public function loadRoot($name, $componentAlias)
{
// get the connection for the component
$this->conn = Doctrine_Manager::getInstance()
->getConnectionForComponent($name);
$table = $this->conn->getTable($name);
$tableName = $table->getTableName();
// get the short alias for this table
$tableAlias = $this->aliasHandler->getShortAlias($tableName);
// quote table name
$this->parts['from'] = $this->conn->quoteIdentifier($tableName);
if ($this->type === self::SELECT) {
$this->parts['from'] .= ' ' . $tableAlias;
}
$this->tableAliases[$tableAlias] = $componentAlias;
$this->_aliasMap[$componentAlias] = array('table' => $table);
return $table;
}
/** /**
* loads a component * loads a component
* *
@ -1161,57 +1245,6 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable {
} }
$map = $fk->getTable()->inheritanceMap;
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $tname2;
}
if ($fk instanceof Doctrine_Relation_Association) {
$asf = $fk->getAssociationFactory();
$assocTableName = $asf->getTableName();
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $assocTableName;
}
$assocPath = $prevPath . '.' . $asf->getComponentName();
if (isset($this->tableAliases[$assocPath])) {
$assocAlias = $this->tableAliases[$assocPath];
} else {
$assocAlias = $this->aliasHandler->generateShortAlias($assocTableName);
}
$this->parts['join'][$tname][$assocTableName] = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $tname . '.'
. $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'][$tname][$assocTableName] .= ' OR ' . $tname . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign();
}
$this->parts['join'][$tname][$tname2] = $join . $aliasString . ' ON ' . $tname2 . '.'
. $fk->getTable()->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign()
. $joinCondition;
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'][$tname][$tname2] .= ' OR ' . $tname2 . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
}
} else {
$this->parts['join'][$tname][$tname2] = $join . $aliasString
. ' ON ' . $tname . '.'
. $fk->getLocal() . ' = ' . $tname2 . '.' . $fk->getForeign()
. $joinCondition;
}
$this->joins[$tname2] = $prevTable; $this->joins[$tname2] = $prevTable;