Skip to content

Loading…

DDC-762: undefined index errors when the join-column of a relation is NULL #5276

Closed
doctrinebot opened this Issue · 9 comments

2 participants

@doctrinebot

Jira issue originally created by user arnaud-lb:

When the value of the join-column of a relation is NULL, "undefined index" errors are thrown in UnitOfWork::createEntity().

The problem is in BasicEntityPersister::_processSQLResult() ; the attached diff fixed the problem for me.

I reproduce the problem with a code like this :
This triggers an error when the value of the column b_id is NULL.

<?php

class A {
  @Column(name="b_id", type="integer")
  private $bId;

  @OneToOne(targetEntity="B")
  @JoinColumn(name="b_id", referencedColumnName="id")
  private $b;
}

$entityManager->find('A', 1);
?>
@doctrinebot

Comment created by @beberlei:

fixed formating

@doctrinebot

Comment created by @beberlei:

This should either be fixed in MASTER, or is not an issue (redefine of the same column as key and relation). This will really only be possible with the experimental DDC-117 branch that will be merged for 2.1

@doctrinebot

Comment created by arnaud-lb:

not an issue (redefine of the same column as key and relation)

My example was not clear enough, the column is not a key.

<?php

class A {

  @Id
  private $id;

  // apart being a foreign key, this is not a key of A
  @Column(name="b_id", type="integer")
  private $bId;

  @OneToOne(targetEntity="B")
  @JoinColumn(name="b_id", referencedColumnName="id")
  private $b;
}

$entityManager->find('A', 1);
?>
@doctrinebot

Comment created by @beberlei:

problem is that arraykeyexists is 9 times slower than isset, and this method is easily called several thousand times. We need to find another solution

@doctrinebot

Comment created by @beberlei:

@roman my proposed patch is this:

diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index 242d84b..e3cd015 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
<ins></ins><ins> b/lib/Doctrine/ORM/UnitOfWork.php
@@ -1881,7 </ins>1881,7 @@ class UnitOfWork implements PropertyChangedListener
                         if ($assoc['isOwningSide']) {
                             $associatedId = array();
                             foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
-                                $joinColumnValue = $data[$srcColumn];
+                                $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null;
                                 if ($joinColumnValue !== null) {
                                     $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue;
                                 }

it sucks this applies only to this use-case however...

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by arnaud-lb:

Thanks!

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.