Skip to content

Loading…

DDC-849: PersistentCollection::clear() doesn't clear the collection #5369

Closed
doctrinebot opened this Issue · 9 comments

1 participant

@doctrinebot

Jira issue originally created by user enumag:

Clearing ManyToMany association doesn't work. I needed to clear the roles of the user (after form submit) and then add the checked roles. Also counting them doesn't work properly.

See the clearRoles method in the attachment.

//EDIT: Don't know if it's important but the association is bidirectional.

@doctrinebot

Comment created by romanb:

Can you provide more context, like the code that is using the entity? Thanks.

@doctrinebot

Comment created by enumag:

Code is something like this:

<?php
//$user is instance of UserEntity from the attachment
$user->clearRoles();

//$role is instance of RoleEntity which is in bidirectional association wirth user
//$role sometimes is one of those previously cleared (assume it is for this example)
if (...) {
    $user->addRole($role);
/* which calles this:
    public function addRole(RoleEntity $entity) {
        //contains method is false positive (the entity was removed by clear, but contains still returns TRUE)
        if (!$this->roles->contains($entity)) {
            $this->roles[] = $entity;
        }
        return $this;
    }
*/
}

//$em is instance of EntityManager
$em->flush();
?>

Ultimately count method returns wrong number and contains is false positive. I know that when i don't use the contains condition it works but that's not the point.

@doctrinebot

Comment created by @beberlei:

Sorry, but isn't then PersistentCollection::remove() and ::contains() wrong not clear()?

I think i have a good grasp on the issue and try to reproduce it.

@doctrinebot

Comment created by @beberlei:

I added a testcase tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php that shows everything is working correctly. I cannot reproduce your problem.

Can you try to extend this phpunit testcase to show the failure?

I downgrade to trivial and detach the issue from RC1

@doctrinebot

Comment created by @beberlei:

Duplicate to DDC-1189

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0.7 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.