/** * Deletes removed elements from a PersistentCollection instance. * * This method is intended to be used with the "pushAll" and "addToSet" * strategies. * * @param PersistentCollection $coll * @param array $options */ private function deleteElements(PersistentCollection $coll, array $options) { $deleteDiff = $coll->getDeleteDiff(); if (empty($deleteDiff)) { return; } list($propertyPath, $parent) = $this->getPathAndParent($coll); $query = array('$unset' => array()); foreach ($deleteDiff as $key => $document) { $query['$unset'][$propertyPath . '.' . $key] = true; } $this->executeQuery($parent, $query, $options); /** * @todo This is a hack right now because we don't have a proper way to * remove an element from an array by its key. Unsetting the key results * in the element being left in the array as null so we have to pull * null values. */ $this->executeQuery($parent, array('$pull' => array($propertyPath => null)), $options); }