DDC-839: Error when trying to update PersistentCollection #5359

doctrinebot opened this Issue Oct 15, 2010 · 5 comments

2 participants


Jira issue originally created by user vigor_bg:

This is the error that i get :
"Argument 1 passed to Doctrine\ORM\UnitOfWork::getCollectionPersister() must be an array, null given, called in /home/vis/projects/CRM/trunk/library/Doctrine/ORM/UnitOfWork.php on line 302 and defined at /home/vis/projects/CRM/trunk/library/Doctrine/ORM/UnitOfWork.php:2149"

This happens when i try to update Entity that have PersistentCollection but when i was creating the entity did not create entities to be attached to it by the PersistentCollection. Later on i called it and and used :

$collectionEntity = $em->getRepository('CollectionEntityName')->findOneBy($data);
$entity                   = $em->getRepository('EntityName')->findOneBy($entityData);

Comment created by vigor_bg:

After some investigating i did find a solution that seems to work.
In Doctrine\ORM\UnitOfWork;
in the function computeChangeSet()

from line 482

 // Look for changes in associations of the entity
        foreach ($class->associationMappings as $field => $assoc) {
            $val = $class->reflFields[$field]->getValue($entity);
            if ($val !== null) {

                 * Fix done by Victor on 15.10.2010
                if ($val instanceof PersistentCollection) {
                    $val->setOwner($entity, $assoc);
                 * End Fix

                $this->computeAssociationChanges($assoc, $val);


That way i make sure that the owner for the PersistentCollection is set for sure and when it is called in the commit function it does not give errors.

Hope that this solution will work for you. :)


Comment created by seldaek:

I hit the same issue, if a many-to-many's collection is empty (either at the firstr creation or if you clear()'d it later on), and then you add() something to it and try to flush, it does not know its parent.

Victor's fix has also been verified here. Not sure if it's the best way, but it's working. Please fix this asap because it's essentially preventing relations to be used for me. I had to resort to a ugly hack for the time being to always have one item in the association that is hidden..


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone 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