Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 5 comments

2 participants

@doctrinebot

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);
$entity->getCollection()->add($collectionEntity);
$em->presist();
$em->flush();
@doctrinebot

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. :)

@doctrinebot

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..

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 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.