-
-
Save doctrinebot/0a176fb34a6bb72df41d to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-849 - https://github.com/doctrine/doctrine2/issues/5369
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Entity | |
* @Table(name = "user") | |
* @property string $name | |
* @property-write string $password | |
* @property-read Doctrine\Common\Collections\Collection $roles | |
*/ | |
class UserEntity | |
{ | |
//... | |
/** | |
* @ManyToMany(targetEntity = "RoleEntity") | |
* @JoinTable(name = "user_role", | |
* joinColumns = {@JoinColumn(name = "user")}, | |
* inverseJoinColumns = {@JoinColumn(name = "role")} | |
* ) | |
* @var Doctrine\Common\Collections\Collection | |
*/ | |
private $roles; | |
public function __construct() { | |
//... | |
$this->roles = new ArrayCollection; | |
} | |
public function getRoles() { | |
return $this->roles; | |
} | |
public function addRole(RoleEntity $entity) { | |
if (!$this->roles->contains($entity)) { | |
$this->roles[] = $entity; | |
} | |
return $this; | |
} | |
public function clearRoles() { | |
$this->roles->clear(); //This should remove all roles, $this->roles->count() should always be 0 | |
if ($this->roles->count() > 0) { //but it isn't | |
throw new Exception("Roles are not empty after clear."); | |
} | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment