mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
PersistentCollection::clear does not clear the collection #1039
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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; } //... }@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.