parent
7b84d15530
commit
1a0179bdce
@ -52,5 +52,39 @@ class Doctrine_Association_Self extends Doctrine_Association {
|
||||
|
||||
return $dql;
|
||||
}
|
||||
|
||||
|
||||
public function fetchRelatedFor(Doctrine_Record $record) {
|
||||
$id = $record->getIncremented();
|
||||
|
||||
$q = new Doctrine_RawSql();
|
||||
|
||||
$assocTable = $this->getAssociationFactory()->getTableName();
|
||||
$tableName = $record->getTable()->getTableName();
|
||||
$identifier = $record->getTable()->getIdentifier();
|
||||
|
||||
$sub = "SELECT ".$this->getForeign().
|
||||
" FROM ".$assocTable.
|
||||
" WHERE ".$this->getLocal().
|
||||
" = ?";
|
||||
|
||||
$sub2 = "SELECT ".$this->getLocal().
|
||||
" FROM ".$assocTable.
|
||||
" WHERE ".$this->getForeign().
|
||||
" = ?";
|
||||
|
||||
$q->select('{'.$tableName.'.*}, {'.$assocTable.'.*}')
|
||||
->from($tableName.' INNER JOIN '.$assocTable.' ON '.
|
||||
$tableName.'.'.$identifier.' = '.$assocTable.'.'.$this->getLocal().' OR '.
|
||||
$tableName.'.'.$identifier.' = '.$assocTable.'.'.$this->getForeign()
|
||||
)
|
||||
->where($tableName.'.'.$identifier.' IN ('.$sub.') OR '.
|
||||
$tableName.'.'.$identifier.' IN ('.$sub2.')'
|
||||
);
|
||||
$q->addComponent($tableName, $record->getTable()->getComponentName());
|
||||
$q->addComponent($assocTable, $record->getTable()->getComponentName(). '.' . $this->getAssociationFactory()->getComponentName());
|
||||
|
||||
return $q->execute(array($id, $id));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -594,6 +594,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @param $name name of the property
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
public function rawGet($name) {
|
||||
if( ! isset($this->data[$name]))
|
||||
throw new InvalidKeyException();
|
||||
@ -603,6 +604,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* load
|
||||
* loads all the unitialized properties from the database
|
||||
@ -1299,36 +1301,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$coll = $graph->query($query,array($id));
|
||||
$coll->setReference($this, $fk);
|
||||
} elseif($fk instanceof Doctrine_Association_Self) {
|
||||
$id = $this->getIncremented();
|
||||
|
||||
$q = new Doctrine_RawSql();
|
||||
|
||||
$assocTable = $fk->getAssociationFactory()->getTableName();
|
||||
$tableName = $this->getTable()->getTableName();
|
||||
$identifier = $this->getTable()->getIdentifier();
|
||||
|
||||
$sub = "SELECT ".$fk->getForeign().
|
||||
" FROM ".$assocTable.
|
||||
" WHERE ".$fk->getLocal().
|
||||
" = ?";
|
||||
|
||||
$sub2 = "SELECT ".$fk->getLocal().
|
||||
" FROM ".$assocTable.
|
||||
" WHERE ".$fk->getForeign().
|
||||
" = ?";
|
||||
|
||||
$q->select('{'.$tableName.'.*}, {'.$assocTable.'.*}')
|
||||
->from($tableName.' INNER JOIN '.$assocTable.' ON '.
|
||||
$tableName.'.'.$identifier.' = '.$assocTable.'.'.$fk->getLocal().' OR '.
|
||||
$tableName.'.'.$identifier.' = '.$assocTable.'.'.$fk->getForeign()
|
||||
)
|
||||
->where($tableName.'.'.$identifier.' IN ('.$sub.') OR '.
|
||||
$tableName.'.'.$identifier.' IN ('.$sub2.')'
|
||||
);
|
||||
$q->addComponent($tableName, $this->table->getComponentName());
|
||||
$q->addComponent($assocTable, $this->table->getComponentName().'.'.$fk->getAssociationFactory()->getComponentName());
|
||||
|
||||
$coll = $q->execute(array($id, $id));
|
||||
$coll = $fk->fetchRelatedFor($this);
|
||||
} elseif($fk instanceof Doctrine_Association) {
|
||||
$id = $this->getIncremented();
|
||||
$coll = $graph->query($query, array($id));
|
||||
|
Loading…
Reference in New Issue
Block a user