Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-979

ArrayHydrator::updateResultPointer() must be an array, string given

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: Git Master
    • Fix Version/s: 2.2
    • Component/s: DQL, ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MySQL - Ubuntu

      Description

      I have the following MySQL tables + data

      CREATE TABLE `agent` (
        `agentID` bigint(20) NOT NULL AUTO_INCREMENT,
        `company` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`agentID`)
      ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='module=agent';
      
      CREATE TABLE `file` (
        `fileID` bigint(20) NOT NULL AUTO_INCREMENT,
        `filename` varchar(100) DEFAULT NULL,
        `mimetype` varchar(100) DEFAULT NULL,
        `extension` varchar(5) DEFAULT NULL,
        `path` varchar(255) DEFAULT NULL,
        PRIMARY KEY (`fileID`)
      ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='module=agent';
      
      CREATE TABLE `agentFile` (
        `agentID` bigint(20) NOT NULL COMMENT 'orderBy=orderNr&order=asc',
        `fileID` bigint(20) NOT NULL,
        `orderNr` int(11) DEFAULT NULL,
        PRIMARY KEY (`agentID`,`fileID`),
        KEY `agentFileAgent` (`agentID`),
        KEY `agentFileFile` (`fileID`),
        CONSTRAINT `agentFileAgent` FOREIGN KEY (`agentID`) REFERENCES `agent` (`agentID`) ON DELETE CASCADE ON UPDATE NO ACTION,
        CONSTRAINT `agentFileFile` FOREIGN KEY (`fileID`) REFERENCES `file` (`fileID`) ON DELETE CASCADE ON UPDATE NO ACTION
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module=agent';
      
      
      INSERT INTO `agent` (agentID,company) VALUES (1,'Company 1');
      INSERT INTO `agent` (agentID,company) VALUES (2,'Company 2');
      INSERT INTO `file` (fileID,filename,mimetype,extension,path) VALUES (1,'logoCompany2',NULL,NULL,NULL);
      INSERT INTO `agentFile` (agentID,fileID,orderNr) VALUES (2,1,0);
      

      Everything works fine if I do the following:

      $query = $em->createQuery('SELECT a, af, f FROM Agent_Model_Agent a LEFT JOIN a._agentFileRefAgent af WITH af._orderNr=0 LEFT JOIN af._file f');
      $results = $query->getResult();
      

      But I get an error when I replace getResult with getArrayResult.

      $query = $em->createQuery('SELECT a, af, f FROM Agent_Model_Agent a LEFT JOIN a._agentFileRefAgent af WITH af._orderNr=0 LEFT JOIN af._file f');
      $results = $query->getArrayResult();
      

      Error:

      Catchable fatal error: Argument 1 passed to Doctrine\ORM\Internal\Hydration\ArrayHydrator::updateResultPointer() must be an array, string given, called in /var/www/vhost/issue/htdocs/externals/Doctrine/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php on line 150 and defined in /var/www/vhost/issue/htdocs/externals/Doctrine/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php on line 207
      0.2773	12011956	Doctrine\ORM\AbstractQuery->getArrayResult( )	../IndexController.php:18
      0.2773	12012164	Doctrine\ORM\AbstractQuery->execute( )	../AbstractQuery.php:378
      0.3262	12217064	Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll( )	../AbstractQuery.php:527
      0.3263	12199568	Doctrine\ORM\Internal\Hydration\ArrayHydrator->_hydrateAll( )	../AbstractHydrator.php:99
      0.3276	12219368	Doctrine\ORM\Internal\Hydration\ArrayHydrator->_hydrateRow( )	../ArrayHydrator.php:62
      0.3277	12223840	Doctrine\ORM\Internal\Hydration\ArrayHydrator->updateResultPointer( )	../ArrayHydrator.php:150
      

        Activity

        Hide
        Guilherme Blanco added a comment -

        Could you please include your Model mappings too?

        Show
        Guilherme Blanco added a comment - Could you please include your Model mappings too?
        Hide
        Guilherme Blanco added a comment - - edited

        Hi,

        This special situation is not really possible.
        You are not allowed to create a cross-reference Entity without defining an own @Id.
        The situation you exposed here is due to it. Issue was left open but now after some tests it can be closed. In 2.2-DEV we added a better explanation for your problem, I hope the message is clear enough for you:

        Entity of type Doctrine\Tests\ORM\Functional\Ticket\DDC979AgentFile has identity through a foreign entity Doctrine\Tests\ORM\Functional\Ticket\DDC979Agent, however this entity has no identity itself. 
        You have to call EntityManager#persist() on the related entity and make sure that an identifier was generated before trying to persist 'Doctrine\Tests\ORM\Functional\Ticket\DDC979AgentFile'. 
        In case of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call EntityManager#flush() between both persist operations.
        

        Marking the issue as won't fix.

        Show
        Guilherme Blanco added a comment - - edited Hi, This special situation is not really possible. You are not allowed to create a cross-reference Entity without defining an own @Id. The situation you exposed here is due to it. Issue was left open but now after some tests it can be closed. In 2.2-DEV we added a better explanation for your problem, I hope the message is clear enough for you: Entity of type Doctrine\Tests\ORM\Functional\Ticket\DDC979AgentFile has identity through a foreign entity Doctrine\Tests\ORM\Functional\Ticket\DDC979Agent, however this entity has no identity itself. You have to call EntityManager#persist() on the related entity and make sure that an identifier was generated before trying to persist 'Doctrine\Tests\ORM\Functional\Ticket\DDC979AgentFile'. In case of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call EntityManager#flush() between both persist operations. Marking the issue as won't fix.
        Hide
        Guilherme Blanco added a comment -

        Added the testcase I have used.

        Show
        Guilherme Blanco added a comment - Added the testcase I have used.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Van Hauwaert Bert
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: