本文整理汇总了PHP中Doctrine_Table::getRelation方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Table::getRelation方法的具体用法?PHP Doctrine_Table::getRelation怎么用?PHP Doctrine_Table::getRelation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Table
的用法示例。
在下文中一共展示了Doctrine_Table::getRelation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRelation
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);
}
示例2: populateRelated
/**
* 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);
}
}
}