/** * Remove role of this object * through the role_permission cross reference table. * * @param ChildRole $role * @return ChildPermission The current object (for fluent API support) */ public function removeRole(ChildRole $role) { if ($this->getRoles()->contains($role)) { $rolePermission = new ChildRolePermission(); $rolePermission->setRole($role); if ($role->isPermissionsLoaded()) { //remove the back reference if available $role->getPermissions()->removeObject($this); } $rolePermission->setPermission($this); $this->removeRolePermission(clone $rolePermission); $rolePermission->clear(); $this->collRoles->remove($this->collRoles->search($role)); if (null === $this->rolesScheduledForDeletion) { $this->rolesScheduledForDeletion = clone $this->collRoles; $this->rolesScheduledForDeletion->clear(); } $this->rolesScheduledForDeletion->push($role); } return $this; }