What do you do in this foreach? Is $query->getResult() return an ArrayCollection? Why you can't return $query->getResult()?