public function initialize()
{
if (!$this->isInitialized) {
$this->isInitialized = true;
$elements = $this->col->toArray();
$this->col->clear();
$relatedObjects = $this->dm->createNativeQuery('doctrine_associations', 'inverse_associations')->setStartKey(array($this->owningDocumentId, $this->assoc['mappedBy']))->setEndKey(array($this->owningDocumentId, $this->assoc['mappedBy'], 'z'))->setIncludeDocs(true)->execute();
$uow = $this->dm->getUnitOfWork();
foreach ($relatedObjects as $relatedRow) {
$this->col->add($uow->createDocument($this->assoc['targetDocument'], $relatedRow['doc']));
}
// append old elements
foreach ($elements as $object) {
$this->col->add($object);
}
}
}