DDC-173: Collection does not get turned into a PersistentCollection when loaded from a proxy #214

Open
opened 2026-01-22 12:30:56 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 24, 2009).

Jira issue originally created by user ablock:

We have two entities, a BugReport and a Reporter. The BugReport holds a reference to a Reporter, and the Reporter holds a reference to all his bug reports:

/****
 * @Entity
 */
class Reporter {
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    public $id;

    /****
     * @OneToMany(targetEntity="BugReport", mappedBy="reporter")
     */
    public $bugReports;

    public function **construct() {
        $this->bugReports = new \Doctrine\Common\Collections\ArrayCollection;
    }
}


/****
 * @Entity
 */
class BugReport {
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    public $id;

    /****
     * @OneToOne(targetEntity="Reporter")
     * @JoinColumn(name="reporter_id", referencedColumnName="id")
     */
    public $reporter;
}

$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array(
  $em->getClassMetadata('Entities\Reporter'),
  $em->getClassMetadata('Entities\BugReport')
);
$tool->createSchema($classes);

$reporter = new Reporter();
$bug = new BugReport();
$bug->reporter = $reporter;

$bug2 = new BugReport();
$bug2->reporter = $reporter;

$em->persist($reporter);
$em->persist($bug);
$em->persist($bug2);

$em->flush();

$reporterId = $reporter->id;
$bug1Id = $bug->id;
$bug2Id = $bug2->id;

$em->clear();

$reporter = $em->find('Entities\Reporter', $reporterId);

echo get_class($reporter->bugReports);

$em->clear();

$bug = $em->find('Entities\BugReport', $bug1Id);

echo get_class($bug->reporter->bugReports);

This outputs "Doctrine\ORM\PersistentCollectionDoctrine\Common\Collections\ArrayCollection"

It seems that when the Reporter is loaded from a Proxy, the fields don't get turned into "managed fields"

Originally created by @doctrinebot on GitHub (Nov 24, 2009). Jira issue originally created by user ablock: We have two entities, a BugReport and a Reporter. The BugReport holds a reference to a Reporter, and the Reporter holds a reference to all his bug reports: ``` /**** * @Entity */ class Reporter { /**** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; /**** * @OneToMany(targetEntity="BugReport", mappedBy="reporter") */ public $bugReports; public function **construct() { $this->bugReports = new \Doctrine\Common\Collections\ArrayCollection; } } /**** * @Entity */ class BugReport { /**** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; /**** * @OneToOne(targetEntity="Reporter") * @JoinColumn(name="reporter_id", referencedColumnName="id") */ public $reporter; } $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array( $em->getClassMetadata('Entities\Reporter'), $em->getClassMetadata('Entities\BugReport') ); $tool->createSchema($classes); $reporter = new Reporter(); $bug = new BugReport(); $bug->reporter = $reporter; $bug2 = new BugReport(); $bug2->reporter = $reporter; $em->persist($reporter); $em->persist($bug); $em->persist($bug2); $em->flush(); $reporterId = $reporter->id; $bug1Id = $bug->id; $bug2Id = $bug2->id; $em->clear(); $reporter = $em->find('Entities\Reporter', $reporterId); echo get_class($reporter->bugReports); $em->clear(); $bug = $em->find('Entities\BugReport', $bug1Id); echo get_class($bug->reporter->bugReports); ``` This outputs "Doctrine\ORM\PersistentCollectionDoctrine\Common\Collections\ArrayCollection" It seems that when the Reporter is loaded from a Proxy, the fields don't get turned into "managed fields"
admin added the Bug label 2026-01-22 12:30:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#214