Commit d6eb961c authored by zYne's avatar zYne

loadRelated() now works for many-to-many associations

parent 7ef7031c
......@@ -45,13 +45,16 @@ class Doctrine_Association extends Doctrine_Relation {
" WHERE ".$this->local.
" IN (".substr(str_repeat("?, ", $count),0,-2).")";
switch($context):
case "record":
$dql = "FROM ".$this->table->getComponentName();
if($context != 'record')
$dql .= ":".$this->associationTable->getComponentName();
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier().
" IN ($sub)";
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)";
break;
case "collection":
$dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName();
$dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)";
endswitch;
return $dql;
}
......
......@@ -624,9 +624,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list[] = $value;
endforeach;
}
$rel = $this->table->getRelation($name);
$dql = $rel->getRelationDql(count($list), 'collection');
$coll = $query->query($dql, $list);
$coll = $query->query($dql, $list);
$this->populateRelated($name, $coll);
}
/**
......@@ -677,16 +678,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
continue;
$sub = new Doctrine_Collection($table);
$association = $asf->getComponentName();
foreach($coll as $k => $related) {
if($related[$association][0]->get($local) == $record[$identifier]) {
$sub->add($related);
$coll->remove($k);
if($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name));
}
}
$this->data[$key]->setRelated($name, $sub);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment