Hi,

I have an entity Group and an entity Member. Group to Member is a OneToMany 
bidirectional relationship. That makes the ManyToOne relationship defined 
on Member the owning side is the. My question is how can I have code that 
moves a member to another group. For example:

class Group
{
    
    private $id;
    private $members;
    
    public function __construct()
    {
        $this->members = new ArrayCollection();
    }

    public function moveMembersToAnotherGroup(array $ids): self
    {
        $newGroup = new self();
        
        foreach ($ids as $id) {
            $member = $this->members->get($id);
            $this->members->remove($id);
            $member->setGroup($newGroup);
        }
        
        return $newGroup;
    }
}

class Member
{
    
    private $id;
    private $group;

    public function setGroup(Group $group)
    {
        $this->group = $group;
    }
}

$group = $groupRepo->ofId(1);
$newGroup = $group->moveMembersToAnotherGroup([1, 2]);

$groupRepo->save($group);
$groupRepo->save($newGroup);


Is such a thing possible with Doctrine 2? If yes, how? 

Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/doctrine-user/3df3b19f-042f-49c4-a818-8cb191d54a47%40googlegroups.com.

Reply via email to