/** * Remove group of this object * through the kk_user_group cross reference table. * * @param ChildGroup $group * @return ChildUser The current object (for fluent API support) */ public function removeGroup(ChildGroup $group) { if ($this->getGroups()->contains($group)) { $userGroup = new ChildUserGroup(); $userGroup->setGroup($group); if ($group->isUsersLoaded()) { //remove the back reference if available $group->getUsers()->removeObject($this); } $userGroup->setUser($this); $this->removeUserGroup(clone $userGroup); $userGroup->clear(); $this->collGroups->remove($this->collGroups->search($group)); if (null === $this->groupsScheduledForDeletion) { $this->groupsScheduledForDeletion = clone $this->collGroups; $this->groupsScheduledForDeletion->clear(); } $this->groupsScheduledForDeletion->push($group); } return $this; }