DDC-568: Notice 'Undefined index' in UnitOfWork when hydrating partial objects with OneToOne assoc (owning side) #5074

doctrinebot opened this Issue May 3, 2010 · 6 comments

2 participants


Jira issue originally created by user 7heaven:

There's an object with OneToOne association (the owning side).
When trying to hydrate it using partial query NOTICE is outputted.

Notice: undefined index [*FK column_name of OneToOne assoc*] in UnitOfWork on line: 1773

Probably, the reason is in the way Query calls hydrator's iterate method (with no hints passed to it). Therefore the UnitOfWork object is not affected by HINTFORCE_PARTIALLOAD hint set to the query object.

Suggested solution:
pass _hints array to a hydrator::iterate method when calling it from an AbstractQuery::iterate method.

public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
        return $this->*em->newHydrator($this->*hydrationMode)->iterate(
            $this->*doExecute($params, $hydrationMode), $this->_resultSetMapping, /* HERE IT IS ----> */ $this->*hints /** <-------- **/

Am I right?


Comment created by romanb:

Can we see the code you're using? We need to create a testcase first before fixing it.

The code example in the documentation is no longer correct. I updated it already but the docs did not regenerate yet.

For partial objects, you need to use "select partial u.{id,name} from User u".

The HINTFORCE_PARTIALLOAD now actually means "no proxies" or "optimize everything possible". It really needs to be renamed :)


Comment created by 7heaven:

"select partial u.{id,name} from User u"
Use of PARTIAL keyword is possible for DQL queries. How it could be done using native sql queries?

Here is a reproducible test case using sandbox data model:

$userA = new \Entities\User();
$userA->setName("user A");
$userA->setTest("test A");


$sql = "SELECT u.id, u.name, u.test FROM users u";
$rsMapping = new \Doctrine\ORM\Query\ResultSetMapping();
$rsMapping->addEntityResult("Entities\User", "u");
$rsMapping->addFieldResult("u", "id", "id");
$rsMapping->addFieldResult("u", "name", "name");
$rsMapping->addFieldResult("u", "test", "test");

$query = $em->createNativeQuery($sql, $rsMapping);

// Without fix in AbstractQuery::iterate() described above this is of no use
$query->setHint(\Doctrine\ORM\Query::HINT*FORCE_PARTIAL*LOAD, true);

$iterableResult = $query->iterate();
foreach ($iterableResult as $row) {
    $user = $row[0];
    echo "<pre>";
    echo "</pre>";


Listed code outputs this:

Notice: Undefined index: address_id in *****\Doctrine\ORM\UnitOfWork.php on line 1773

object(stdClass)#66 (5) {
  string(13) "Entities\User"
  string(6) "user A"
  string(6) "test A"

Comment created by 7heaven:

Improved formatting and code highlighting.


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-BETA2 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment