loadRelated() now works for many-to-many associations
This commit is contained in:
parent
7ef7031c37
commit
d6eb961c0c
@ -45,13 +45,16 @@ class Doctrine_Association extends Doctrine_Relation {
|
|||||||
" WHERE ".$this->local.
|
" WHERE ".$this->local.
|
||||||
" IN (".substr(str_repeat("?, ", $count),0,-2).")";
|
" IN (".substr(str_repeat("?, ", $count),0,-2).")";
|
||||||
|
|
||||||
$dql = "FROM ".$this->table->getComponentName();
|
switch($context):
|
||||||
|
case "record":
|
||||||
if($context != 'record')
|
$dql = "FROM ".$this->table->getComponentName();
|
||||||
$dql .= ":".$this->associationTable->getComponentName();
|
$dql .= ":".$this->associationTable->getComponentName();
|
||||||
|
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)";
|
||||||
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier().
|
break;
|
||||||
" IN ($sub)";
|
case "collection":
|
||||||
|
$dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName();
|
||||||
|
$dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)";
|
||||||
|
endswitch;
|
||||||
|
|
||||||
return $dql;
|
return $dql;
|
||||||
}
|
}
|
||||||
|
@ -624,9 +624,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
$list[] = $value;
|
$list[] = $value;
|
||||||
endforeach;
|
endforeach;
|
||||||
}
|
}
|
||||||
|
$rel = $this->table->getRelation($name);
|
||||||
$dql = $rel->getRelationDql(count($list), 'collection');
|
$dql = $rel->getRelationDql(count($list), 'collection');
|
||||||
|
|
||||||
$coll = $query->query($dql, $list);
|
$coll = $query->query($dql, $list);
|
||||||
|
|
||||||
$this->populateRelated($name, $coll);
|
$this->populateRelated($name, $coll);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -677,16 +678,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
$sub = new Doctrine_Collection($table);
|
$sub = new Doctrine_Collection($table);
|
||||||
$association = $asf->getComponentName();
|
|
||||||
|
|
||||||
foreach($coll as $k => $related) {
|
foreach($coll as $k => $related) {
|
||||||
if($related[$association][0]->get($local) == $record[$identifier]) {
|
if($related->get($local) == $record[$identifier]) {
|
||||||
$sub->add($related);
|
$sub->add($related->get($name));
|
||||||
$coll->remove($k);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data[$key]->setRelated($name, $sub);
|
$this->data[$key]->setRelated($name, $sub);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user