/** * @{inheritDoc} */ public function getIterator() { if ($this->queryBuilder) { return new CollectionMapIterator($this->queryBuilder->getQuery()->iterate(), function ($row) { $entity = $row[0]; if ($this->detaching) { $this->queryBuilder->getEntityManager()->detach($entity); } return $entity; }); } else { return parent::getIterator(); } }