Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-76

I get an error when trying to persist a document

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      This is the error I get:

      get_class() expects parameter 1 to be object, array given.

      Stack Trace:

      #0 [internal function]: {closure}(2, 'get_class() exp...', '/Library/WebSer...', 562, Array)
      #1 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php(562): get_class(Array)
      #2 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php(545): Doctrine\ODM\MongoDB\Persisters\BasicDocumentPersister->prepareReferencedDocValue(Array, Array)
      #3 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php(536): Doctrine\ODM\MongoDB\Persisters\BasicDocumentPersister->prepareValue(Array, Array)
      #4 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php(463): Doctrine\ODM\MongoDB\Persisters\BasicDocumentPersister->prepareValue(Array, Array)
      #5 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php(209): Doctrine\ODM\MongoDB\Persisters\BasicDocumentPersister->prepareUpdateData(Object(App_Model_Ticket))
      #6 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/UnitOfWork.php(771): Doctrine\ODM\MongoDB\Persisters\BasicDocumentPersister->update(Object(App_Model_Ticket), Array)
      #7 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/UnitOfWork.php(281): Doctrine\ODM\MongoDB\UnitOfWork->executeUpdates(Object(Doctrine\ODM\MongoDB\Mapping\ClassMetadata), Array)
      #8 /Library/WebServer/Documents/ktapi/library/Doctrine/ODM/MongoDB/DocumentManager.php(503): Doctrine\ODM\MongoDB\UnitOfWork->commit(Array)
      #9 /Library/WebServer/Documents/ktmodels/library/App/Model/Service/Dao/Doctrine.php(26): Doctrine\ODM\MongoDB\DocumentManager->flush()
      #10 /Library/WebServer/Documents/ktmodels/library/App/Model/Service/Abstract.php(54): App_Model_Service_Dao_Doctrine->save(Object(App_Model_Ticket))
      #11 /Library/WebServer/Documents/ktmodels/library/App/Model/Abstract.php(215): App_Model_Service_Abstract->save(Object(App_Model_Ticket))
      #12 /Library/WebServer/Documents/ktmodels/library/App/Model/Ticket.php(84): App_Model_Abstract->save()
      #13 /Library/WebServer/Documents/ktapi/application/controllers/TicketController.php(145): App_Model_Ticket->save()
      #14 /Library/WebServer/Documents/ktapi/library/Zend/Controller/Action.php(513): TicketController->putAction()
      #15 /Library/WebServer/Documents/ktapi/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('putAction')
      #16 /Library/WebServer/Documents/ktapi/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
      #17 /Library/WebServer/Documents/ktapi/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
      #18 /Library/WebServer/Documents/ktapi/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
      #19 /Library/WebServer/Documents/ktapi/public/index.php(34): Zend_Application->run()
      #20 {main}
      

      Please tell me how I can be more precise or of more help. Do you need my models for debugging? (I do not want to post them here).

        Activity

        Hide
        Sebastian Hoitz added a comment -

        Resolved with this commit:

        http://github.com/sebastianhoitz/mongodb-odm/commit/9ec340697b184284f420e077457127f3147566e0

        Includes test case to reproduce the issue.

        Show
        Sebastian Hoitz added a comment - Resolved with this commit: http://github.com/sebastianhoitz/mongodb-odm/commit/9ec340697b184284f420e077457127f3147566e0 Includes test case to reproduce the issue.
        Hide
        Sebastian Hoitz added a comment -

        I changed the prepareReferencedDocValue method in BasicDocumentPersister.php to this:

        private function prepareReferencedDocValue(array $referenceMapping, $document)
        	{
        		$id = null;
        
        		if (is_array($document))
        		{
        			$className = $referenceMapping['targetDocument'];
        		}
        		else
        		{
        			$className = get_class($document);
        			$id = $this->uow->getDocumentIdentifier($document);
        		}
        
        		$class = $this->dm->getClassMetadata($className);
        
        		if (null !== $id)
        		{
        			$id = $class->getDatabaseIdentifierValue($id);
        		}
        		$ref = array(
        				$this->cmd . 'ref' => $class->getCollection(),
        				$this->cmd . 'id' => $id,
        				$this->cmd . 'db' => $class->getDB()
        		);
        		if (!isset($referenceMapping['targetDocument']))
        		{
        			$discriminatorField = isset($referenceMapping['discriminatorField']) ? $referenceMapping['discriminatorField'] : '_doctrine_class_name';
        			$discriminatorValue = isset($referenceMapping['discriminatorMap']) ? array_search($class->getName(), $referenceMapping['discriminatorMap']) : $class->getName();
        			$ref[$discriminatorField] = $discriminatorValue;
        		}
        		return $ref;
        	}
        

        and this seems to solve the issue.

        However, I was not able to get the whole Doctrine ODM unit testing set up, so I could not check if all unit tests still pass.

        I would love if somebody could help me getting the github and unit testing environment for Doctrine set up, so that I can work on some issues too!

        Show
        Sebastian Hoitz added a comment - I changed the prepareReferencedDocValue method in BasicDocumentPersister.php to this: private function prepareReferencedDocValue(array $referenceMapping, $document) { $id = null ; if (is_array($document)) { $className = $referenceMapping['targetDocument']; } else { $className = get_class($document); $id = $ this ->uow->getDocumentIdentifier($document); } $class = $ this ->dm->getClassMetadata($className); if ( null !== $id) { $id = $class->getDatabaseIdentifierValue($id); } $ref = array( $ this ->cmd . 'ref' => $class->getCollection(), $ this ->cmd . 'id' => $id, $ this ->cmd . 'db' => $class->getDB() ); if (!isset($referenceMapping['targetDocument'])) { $discriminatorField = isset($referenceMapping['discriminatorField']) ? $referenceMapping['discriminatorField'] : '_doctrine_class_name'; $discriminatorValue = isset($referenceMapping['discriminatorMap']) ? array_search($class->getName(), $referenceMapping['discriminatorMap']) : $class->getName(); $ref[$discriminatorField] = $discriminatorValue; } return $ref; } and this seems to solve the issue. However, I was not able to get the whole Doctrine ODM unit testing set up, so I could not check if all unit tests still pass. I would love if somebody could help me getting the github and unit testing environment for Doctrine set up, so that I can work on some issues too!
        Hide
        Sebastian Hoitz added a comment -

        The issue seems to be in this http://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php#L419 method.

        When calculating the changeset we end up with an array. When this array is passed on to prepareValue in http://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php#L464 this method can not handle the array.

        I hope this helps a bit with pinpointing the error.

        Show
        Sebastian Hoitz added a comment - The issue seems to be in this http://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php#L419 method. When calculating the changeset we end up with an array. When this array is passed on to prepareValue in http://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php#L464 this method can not handle the array. I hope this helps a bit with pinpointing the error.
        Hide
        Sebastian Hoitz added a comment -

        I got the latest version from Github and this error still occures.

        I also checked with my models. Before persisting my model with Doctrine all the referenced models are Documents. Somewhere in the Persister the model has to get changed to an array.

        Show
        Sebastian Hoitz added a comment - I got the latest version from Github and this error still occures. I also checked with my models. Before persisting my model with Doctrine all the referenced models are Documents. Somewhere in the Persister the model has to get changed to an array.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Sebastian Hoitz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: