I have a mapping of php objects in a mongodb document (called Node) to a structure
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
class Node{
protected $id;
protected $domain;
protected $items = array();
}
And the referencing document called NodeItem,
class NodeItem {
protected $id;
protected $name;
protected Node;
}
As reflected in the annotation above 'Node', MANY 'NodeItems' links are stored in the $ items array and 'NodeItems' refer to ONE 'Node'. Thus, these are bidirectional reference collections.
My question is how to efficiently remove multiple "NodeItem" documents from its collection (based on an array of available identifiers), so that deleted NodeItem documents are also removed from the links in the $ items array in 'Node' (cascading deletion, I think this is what am I asking for?).
I wrote a function with this code:
$qb = $this->dm->createQueryBuilder('SomeBundleBundle:NodeItem');
foreach($NodeItemsArray as $itemId){
$qb->remove()->field('id')->equals($itemId)->getQuery()->execute();
}
NodeItem, $items 'Node' . , {cascade: persist} , , . Symfony 2.
!