public function getRelation($alias, $recursive = true) { if ($this->hasRelation($alias)) { return parent::getRelation($alias, $recursive); } foreach (ExtensionDefinitionTable::$extensionNamesWithFields as $extension) { if (Doctrine::getTable($extension)->hasRelation($alias)) { return Doctrine::getTable($extension)->getRelation($alias, $recursive); } } return parent::getRelation($alias, $recursive); }
/** * Populate the relationship $name for all records in the passed collection * * @param string $name * @param Doctrine_Collection $coll * @return void */ public function populateRelated($name, Doctrine_Collection $coll) { $rel = $this->_table->getRelation($name); $table = $rel->getTable(); $foreign = $rel->getForeign(); $local = $rel->getLocal(); if ($rel instanceof Doctrine_Relation_LocalKey) { foreach ($this->data as $key => $record) { foreach ($coll as $k => $related) { if ($related[$foreign] == $record[$local]) { $this->data[$key]->setRelated($name, $related); } } } } elseif ($rel instanceof Doctrine_Relation_ForeignKey) { foreach ($this->data as $key => $record) { if ( ! $record->exists()) { continue; } $sub = Doctrine_Collection::create($table); foreach ($coll as $k => $related) { if ($related[$foreign] == $record[$local]) { $sub->add($related); $coll->remove($k); } } $this->data[$key]->setRelated($name, $sub); } } elseif ($rel instanceof Doctrine_Relation_Association) { $identifier = $this->_table->getIdentifier(); $asf = $rel->getAssociationFactory(); $name = $table->getComponentName(); foreach ($this->data as $key => $record) { if ( ! $record->exists()) { continue; } $sub = Doctrine_Collection::create($table); foreach ($coll as $k => $related) { if ($related->get($local) == $record[$identifier]) { $sub->add($related->get($name)); } } $this->data[$key]->setRelated($name, $sub); } } }