Example #1
0
 /**
  * Compute the query to delete all entities wished to be removed
  *
  * @return Query
  */
 protected function computeDeleteQuery()
 {
     $qb = new QueryBuilder();
     $variables = [];
     $idx = 0;
     foreach ($this->scheduledForDelete as $entity) {
         $class = $this->getClass($entity);
         $metadata = $this->metadataRegistry->getMetadata($class);
         $var = 'e' . (string) $idx;
         $idProp = $metadata->getId()->getProperty();
         $id = $this->accessor->getValue($entity, $idProp);
         if ($metadata instanceof NodeMetadata) {
             $qb->matchNode($var, $class, [$idProp => $id]);
         } else {
             $qb->addExpr($qb->expr()->matchNode()->relatedTo($qb->expr()->matchRelationship($var, $class, [$idProp => $id])));
         }
         $variables[] = $var;
         $idx++;
     }
     foreach ($variables as $var) {
         $qb->delete($var);
     }
     return $qb->getQuery();
 }