Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

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;  
}
@doctrinebot

Comment created by @beberlei:

Fixed formatting

@doctrinebot

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

Comment created by @beberlei:

fixed aswell as another nasty bug.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.