As I understood when you query database by repository you get PersistentCollection and when your working with your entities you get ArrayCollection.
so consider I have o
/**
* @param Doctrine\Common\Collections\Collection $users
* @return $this
*/
public function setChildren(Doctrine\Common\Collections\Collection $users)
{
$this->children = $users;
return $this;
}
If you look deep into Doctrine Classes you will see the following structure:
Array collection is class that implements interface Collection:
class ArrayCollection implements Collection, Selectable
PersistentCollection is class that extentds AbstractLazyCollection:
final class PersistentCollection extends AbstractLazyCollection implements Selectable
but AbstractLazyCollection implements Collection:
abstract class AbstractLazyCollection implements Collection
So:
Collection is interface, that you should use in method setChildren()
.
This is because of doctrine use lazy loading - mechanism that allow to load not all properties, but only these, that are needed.
Similar question:
Doctrine manyToMany return PersistentCollection instead of ArrayCollection