DDC-2598: Entity removal not persisted when orphanRemoval set to false #3327

Closed
doctrinebot opened this Issue Aug 7, 2013 · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user sparrow:

I have a User class related to UserRole class. The second one is in relations with other entities also.
When I remove a UserRole from collection like below the removal is not persisted to the database unless I specify the orphanRemoval to true (on its mapping).
This seems weird because this is not the case of a User removal but the related UserRole. I think it is because the UserRole is in relation to other Entities which makes doctrine think I might be necessary to keep it in database.

    /****
     * @ORM\OneToMany(targetEntity="UserRole", mappedBy="user", cascade={"persist", "remove"})
     */
    private $userRoles;

        $roles = $user->getUserRoles();
        $roles->removeElement($roles[0]);

//      $role = new UserRole();
//      $role->setUser($user);
//      $role->setRole($em->find('Application\Entity\Role', 2));
//      $roles->add($role);

        $em->flush();
@doctrinebot

Comment created by @ocramius:

Removing an entity from an association has nothing to do with deleting it.

That's exactly what orphan removal achieves instead.

Additionally, in your example, you are not updating the owning side of the association when dissociating users from roles

@doctrinebot

Issue was closed with resolution "Invalid"

@Ocramius Ocramius was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment