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

Closed
opened 2026-01-22 12:56:17 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 21, 2010).

Originally assigned to: @beberlei on GitHub.

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);
?>
Originally created by @doctrinebot on GitHub (Aug 21, 2010). Originally assigned to: @beberlei on GitHub. 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); ?> ```
admin added the Bug label 2026-01-22 12:56:17 +01:00
admin closed this issue 2026-01-22 12:56:18 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 29, 2010):

Comment created by @beberlei:

fixed formating

@doctrinebot commented on GitHub (Aug 29, 2010): Comment created by @beberlei: fixed formating
Author
Owner

@doctrinebot commented on GitHub (Aug 29, 2010):

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 commented on GitHub (Aug 29, 2010): 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](http://www.doctrine-project.org/jira/browse/DDC-117) branch that will be merged for 2.1
Author
Owner

@doctrinebot commented on GitHub (Aug 29, 2010):

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 commented on GitHub (Aug 29, 2010): 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); ?> ```
Author
Owner

@doctrinebot commented on GitHub (Sep 13, 2010):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Sep 13, 2010): Comment created by @beberlei: problem is that array_key_exists is 9 times slower than isset, and this method is easily called several thousand times. We need to find another solution
Author
Owner

@doctrinebot commented on GitHub (Sep 13, 2010):

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 commented on GitHub (Sep 13, 2010): 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...
Author
Owner

@doctrinebot commented on GitHub (Sep 13, 2010):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Sep 13, 2010): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Sep 13, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Sep 13, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Sep 14, 2010):

Comment created by arnaud-lb:

Thanks!

@doctrinebot commented on GitHub (Sep 14, 2010): Comment created by arnaud-lb: Thanks!
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/2424b7a5c6b167c2fe37

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/2424b7a5c6b167c2fe37 - [10747_patch.diff](https://gist.github.com/2424b7a5c6b167c2fe37#file-10747_patch-diff)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#938