DDC-833: Internal Collection of a PersistentCollection is an Entity #1030

Closed
opened 2026-01-22 12:59:22 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 7, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jeffreiffers:

The creation of an Associated Collection of a Proxy Class is broken by this line:

$reflField->getValue($entity) ?: new ArrayCollection

$entity is a Proxy Class and the property is the field users. The function ReflectionProperty::getValue() will return an Entity User. This results that the internal collection of the PersistenCollection is an Entity. This results in:

Fatal error: Call to undefined method Entity\User::clear() in \library\Doctrine\ORM\PersistentCollection.php on line 206

This is my Entity Configuration

class Organization {
    /****
     * @OneToMany(targetEntity="User", mappedBy="organization", cascade={"persist", "remove"})
     */
    private $users;    

    public function **constructor() {
      $this->users = new ArrayCollection();
   }
}

class User {
    /****
     * @ManyToOne(targetEntity="Organization", inversedBy="users")
     * @JoinColumn(name="organization_id", referencedColumnName="id")
     */ 
    private $organization;  
}
Originally created by @doctrinebot on GitHub (Oct 7, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jeffreiffers: The creation of an Associated Collection of a Proxy Class is broken by this line: ``` $reflField->getValue($entity) ?: new ArrayCollection ``` $entity is a Proxy Class and the property is the field users. The function ReflectionProperty::getValue() will return an Entity User. This results that the internal collection of the PersistenCollection is an Entity. This results in: ``` Fatal error: Call to undefined method Entity\User::clear() in \library\Doctrine\ORM\PersistentCollection.php on line 206 ``` This is my Entity Configuration ``` class Organization { /**** * @OneToMany(targetEntity="User", mappedBy="organization", cascade={"persist", "remove"}) */ private $users; public function **constructor() { $this->users = new ArrayCollection(); } } class User { /**** * @ManyToOne(targetEntity="Organization", inversedBy="users") * @JoinColumn(name="organization_id", referencedColumnName="id") */ private $organization; } ```
admin added the Bug label 2026-01-22 12:59:22 +01:00
admin closed this issue 2026-01-22 12:59:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

Comment created by @beberlei:

Fixed formatting

@doctrinebot commented on GitHub (Oct 11, 2010): Comment created by @beberlei: Fixed formatting
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

Comment created by @beberlei:

I don't understand why this $reflField->getValue() returns a user entity. It should only return either NULL or a collection.

@doctrinebot commented on GitHub (Oct 11, 2010): Comment created by @beberlei: I don't understand why this $reflField->getValue() returns a user entity. It should only return either NULL or a collection.
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

Comment created by @beberlei:

fixed aswell as another nasty bug.

@doctrinebot commented on GitHub (Oct 11, 2010): Comment created by @beberlei: fixed aswell as another nasty bug.
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 11, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1030