public function removeTopicFromAllArticles($topicId) { $qb = $this->em->createQueryBuilder(); $topic = $this->em->getReference('Newscoop\\NewscoopBundle\\Entity\\Topic', $topicId); $children = $this->getTopicRepository()->childrenQuery($topic)->getArrayResult(); $attachedTopics = array(); foreach ($children as $key => $child) { if ($this->isAttached($child['id'])) { $attachedTopics[] = $child['id']; } } $attachedTopics[] = $topicId; $topicsQuery = $qb->delete('Newscoop\\Entity\\ArticleTopic', 'at')->where('at.topic IN (?1)')->setParameter(1, $attachedTopics)->getQuery(); $topicsQuery->execute(); return true; }