Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2106

Notice trying to match a Criteria referencing a managed entity not yet persisted

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Undefined index: (...) in Doctrine/ORM/UnitOfWork.php line 2735
      
      #0 doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2735): Symfony\Component\HttpKernel\Debug\ErrorHandler->handle(8, 'Undefined index...', '/Users/frosas/S...', 2735, Array) 
      #1 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1696): Doctrine\ORM\UnitOfWork->getEntityIdentifier(Object(MyEntity)) 
      #2 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1683): Doctrine\ORM\Persisters\BasicEntityPersister->getIndividualValue(Object(MyEntity)) 
      #3 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(818): Doctrine\ORM\Persisters\BasicEntityPersister->getValue(Object(MyEntity)) 
      #4 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(786): Doctrine\ORM\Persisters\BasicEntityPersister->expandCriteriaParameters(Object(Doctrine\Common\Collections\Criteria)) 
      #5 doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php(835): Doctrine\ORM\Persisters\BasicEntityPersister->loadCriteria(Object(Doctrine\Common\Collections\Criteria)) 
      #6 (...): Doctrine\ORM\PersistentCollection->matching(Object(Doctrine\Common\Collections\Criteria)) 
      #7 (...)
      

      As a workaround I had to control this case explicitly:

      if ($myEntity->getId() === null) return null;
      $criteria = Criteria::create()->where(Criteria::expr()->eq('field', $myEntity));
      return $this->collection->matching($criteria)->first();
      

        Activity

        Francesc Rosàs created issue -
        Francesc Rosàs made changes -
        Field Original Value New Value
        Description Undefined index: (...) in Doctrine/ORM/UnitOfWork.php line 2735

        #0 doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2735): Symfony\Component\HttpKernel\Debug\ErrorHandler->handle(8, 'Undefined index...', '/Users/frosas/S...', 2735, Array)
        #1 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1696): Doctrine\ORM\UnitOfWork->getEntityIdentifier(Object(MyEntity))
        #2 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1683): Doctrine\ORM\Persisters\BasicEntityPersister->getIndividualValue(Object(MyEntity))
        #3 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(818): Doctrine\ORM\Persisters\BasicEntityPersister->getValue(Object(MyEntity))
        #4 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(786): Doctrine\ORM\Persisters\BasicEntityPersister->expandCriteriaParameters(Object(Doctrine\Common\Collections\Criteria))
        #5 doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php(835): Doctrine\ORM\Persisters\BasicEntityPersister->loadCriteria(Object(Doctrine\Common\Collections\Criteria))
        #6 (...): Doctrine\ORM\PersistentCollection->matching(Object(Doctrine\Common\Collections\Criteria))
        #7 (...)
        {noformat}
        Undefined index: (...) in Doctrine/ORM/UnitOfWork.php line 2735

        #0 doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(2735): Symfony\Component\HttpKernel\Debug\ErrorHandler->handle(8, 'Undefined index...', '/Users/frosas/S...', 2735, Array)
        #1 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1696): Doctrine\ORM\UnitOfWork->getEntityIdentifier(Object(MyEntity))
        #2 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(1683): Doctrine\ORM\Persisters\BasicEntityPersister->getIndividualValue(Object(MyEntity))
        #3 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(818): Doctrine\ORM\Persisters\BasicEntityPersister->getValue(Object(MyEntity))
        #4 doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(786): Doctrine\ORM\Persisters\BasicEntityPersister->expandCriteriaParameters(Object(Doctrine\Common\Collections\Criteria))
        #5 doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php(835): Doctrine\ORM\Persisters\BasicEntityPersister->loadCriteria(Object(Doctrine\Common\Collections\Criteria))
        #6 (...): Doctrine\ORM\PersistentCollection->matching(Object(Doctrine\Common\Collections\Criteria))
        #7 (...)
        {noformat}

        As a workaround I had to control this case explicitly:

        {noformat}
        if ($myEntity->getId() === null) return null;
        $criteria = Criteria::create()->where(Criteria::expr()->eq('field', $myEntity));
        return $this->collection->matching($criteria)->first();
        {noformat}
        Alexander made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Benjamin Eberlei made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.4 [ 10321 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Francesc Rosàs
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: