PersistentCollection::clear does not clear the collection #1039

Closed
opened 2026-01-22 12:59:40 +01:00 by admin · 1 comment
Owner

Originally created by @jtousek on GitHub (Oct 17, 2010).

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity(repositoryClass = "AdminRepository")
 * @Table(name = "user")
 */
class UserEntity extends StateEntity
{

    //...

    /**
     * @ManyToMany(targetEntity = "RoleEntity")
     * @JoinTable(name = "user_role",
     *      joinColumns = {@JoinColumn(name = "user")},
     *      inverseJoinColumns = {@JoinColumn(name = "role")}
     *      )
     * @var Doctrine\Common\Collections\ArrayCollection
     */
    private $roles;

    public function __construct() {
        //...
        $this->roles = new ArrayCollection;
    }

    public function clearRoles() {
        $this->roles->clear();
        if ($this->roles->count() > 0) {
            //THE CONDITION ABOVE SHOULD NEVER BE TRUE, BUT IT IS!!
            //don't know if it's important, but the association between users and roles IS bidirectional
            echo 'ERROR!!';
        }
        return $this;
    }

    //...

}
Originally created by @jtousek on GitHub (Oct 17, 2010). <pre> use Doctrine\Common\Collections\ArrayCollection; /** * @Entity(repositoryClass = "AdminRepository") * @Table(name = "user") */ class UserEntity extends StateEntity { //... /** * @ManyToMany(targetEntity = "RoleEntity") * @JoinTable(name = "user_role", * joinColumns = {@JoinColumn(name = "user")}, * inverseJoinColumns = {@JoinColumn(name = "role")} * ) * @var Doctrine\Common\Collections\ArrayCollection */ private $roles; public function __construct() { //... $this->roles = new ArrayCollection; } public function clearRoles() { $this->roles->clear(); if ($this->roles->count() > 0) { //THE CONDITION ABOVE SHOULD NEVER BE TRUE, BUT IT IS!! //don't know if it's important, but the association between users and roles IS bidirectional echo 'ERROR!!'; } return $this; } //... } </pre>
admin closed this issue 2026-01-22 12:59:41 +01:00
Author
Owner

@beberlei commented on GitHub (Oct 31, 2010):

Please report this issue on www.doctrine-project.org/jira - i will close this issue tracker here because we dont use it.

@beberlei commented on GitHub (Oct 31, 2010): Please report this issue on www.doctrine-project.org/jira - i will close this issue tracker here because we dont use it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1039