DDC-1304: Native SQL with addJoinedEntityResult() on outer join causes fatal error #1636

Closed
opened 2026-01-22 13:20:39 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 30, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jreed:

If I do a Native SQL query and use the addJoinedEntityResult() to map a LEFT JOIN entity, for those rows with no joined entity the values are all NULL. This causes a fatal error:

Fatal error: Call to a member function setValue() on a non-object in C:\xampp\htdocs\trunk\winlibrary\doctrine-orm\Doctrine\ORM\PersistentCollection.php on line 168

The offending code is:

// Set back reference to owner
$this->typeClass->reflFields[$this->backRefFieldName]
        ->setValue($element, $this->owner);
$this->em->getUnitOfWork()->setOriginalEntityProperty(
        spl*object*hash($element),
        $this->backRefFieldName,
        $this->owner);

Not sure if there is a better place to fix this, but adding a check solves the problem:

if (isset($this->typeClass->reflFields[$this->backRefFieldName])) {
    // Set back reference to owner
    $this->typeClass->reflFields[$this->backRefFieldName]
            ->setValue($element, $this->owner);
    $this->em->getUnitOfWork()->setOriginalEntityProperty(
            spl*object*hash($element),
            $this->backRefFieldName,
            $this->owner);
}
Originally created by @doctrinebot on GitHub (Jul 30, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jreed: If I do a Native SQL query and use the addJoinedEntityResult() to map a LEFT JOIN entity, for those rows with no joined entity the values are all NULL. This causes a fatal error: Fatal error: Call to a member function setValue() on a non-object in C:\xampp\htdocs\trunk\winlibrary\doctrine-orm\Doctrine\ORM\PersistentCollection.php on line 168 The offending code is: ``` // Set back reference to owner $this->typeClass->reflFields[$this->backRefFieldName] ->setValue($element, $this->owner); $this->em->getUnitOfWork()->setOriginalEntityProperty( spl*object*hash($element), $this->backRefFieldName, $this->owner); ``` Not sure if there is a better place to fix this, but adding a check solves the problem: ``` if (isset($this->typeClass->reflFields[$this->backRefFieldName])) { // Set back reference to owner $this->typeClass->reflFields[$this->backRefFieldName] ->setValue($element, $this->owner); $this->em->getUnitOfWork()->setOriginalEntityProperty( spl*object*hash($element), $this->backRefFieldName, $this->owner); } ```
admin added the Bug label 2026-01-22 13:20:40 +01:00
admin closed this issue 2026-01-22 13:20:40 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 31, 2011):

Comment created by @beberlei:

We use native queries ourself in the DQL Parser. That means your native query mapping has to be wrong somehow.

Without details about the SQL, Mapping and native query its hard to find the "real" issue here. The proposed solution is only a hack to get it working. Closing issue.

@doctrinebot commented on GitHub (Jul 31, 2011): Comment created by @beberlei: We use native queries ourself in the DQL Parser. That means your native query mapping has to be wrong somehow. Without details about the SQL, Mapping and native query its hard to find the "real" issue here. The proposed solution is only a hack to get it working. Closing issue.
Author
Owner

@doctrinebot commented on GitHub (Jul 31, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jul 31, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1636