What is a PersistentCollection? What is a PersistentCollection? symfony symfony

What is a PersistentCollection?


1.Is it normal to have Persistent Collections with a simple One-To-Many?

No, what is normal is the ArrayCollection, i never had to use PersistentCollection before, but it have some useful function that may be of use in some cases.

http://www.doctrine-project.org/api/orm/2.1/class-Doctrine.ORM.PersistentCollection.html

  1. How do those collections may appear? (rather than the usual ArrayCollection)

They are collections also they appear the same as a normal ArrayCollection having entities inside with their type.

  1. Finally, what exactly is the use of a Persistent Collection?

As you can see in the documentation the PersistentCollection have a load of functions which ArrayCollection doesn't have, and PersistentCollection uses the EntityManager which allows an interaction with the database without having to persist, only flushing.


To add to Serrar's description.

PersistentCollections only notes the connection to another Entity. Which is true if you properly made the OneToMany or ManyToOne mapping/link.

use Doctrine\Common\Collections\ArrayCollection;public function __construct(){    $this->comments = new ArrayCollection();}// @ORM\OneToMany(targetEntity="Comments", mappedBy="pages")private $comments;public function getComments(){    return $this->comments;}public function setComments(Comments $comments){    $this->comments = $comments;}

They don't give you the array data.

From the example above use the PageEntity's getComments method to pull in the comments related to the current Page. That assumes you have the page object.Setting up the new ArrayCollection object in the construct is important: Relationship Mapping Metadatalink

Doctrine: Class PersistentCollection - The description at the top describes the purpose.