Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-839

Error when trying to update PersistentCollection

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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();
      

        Issue Links

          Activity

          Hide
          victor Velkov added a comment -

          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.

          Show
          victor Velkov added a comment - 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.
          Hide
          Jordi Boggiano added a comment -

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

          Show
          Jordi Boggiano added a comment - 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..
          Hide
          Benjamin Eberlei added a comment -

          Fixed

          Show
          Benjamin Eberlei added a comment - Fixed

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              victor Velkov
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: