[PR #5714] Fix loading of association with quoted JoinColumn #9701

Open
opened 2026-01-22 16:05:10 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/5714

State: closed
Merged: No


Consider this entity

/**
 * @ORM\Entity
 * @ORM\Table()
 */
class TravelInsurance
{

    /**
     * @ORM\Id
     * @ORM\OneToOne(targetEntity="\Foo\Order\Order")
     * @ORM\JoinColumn(name="`order`", nullable=false)
     * @var \Foo\Order\Order
     *
     * @get
     * @set(visibility='private')
     */
    private $order;

    /**
     * @ORM\Column(type="string", length=255)
     * @var string
     *
     * @get
     * @set(visibility='private')
     */
    private $contactName;
}

Loading this entity fails with error ErrorException: Undefined index: order in...\lib\Doctrine\ORM\Utility\IdentifierFlattener.php:92. The problem is, that data that goes to UoW::createEntity and to flattenIdentifier look like this

array (6)
    contactName => "j8"
    "`order`" => 7050473951

note the backticks around order
If the order column was generic @Column, the backticks would not be there
If order was association but not an ID, the loading would not fail, but silently leave $order = null

The root cause, I think, is in method BaseEntityPersister::getSelectColumnAssociationSQL, where column name added to ResultSetMapping is the quoted version for JoinColumn, but for other ordinary columns it adds non-quoted version. The quoted version is then passed from ObjectHydrator to uow::createEntity and produces the error

This pull should fix the problem, although I'm not entirely sure if this is the only place with this issue.

**Original Pull Request:** https://github.com/doctrine/orm/pull/5714 **State:** closed **Merged:** No --- Consider this entity ``` /** * @ORM\Entity * @ORM\Table() */ class TravelInsurance { /** * @ORM\Id * @ORM\OneToOne(targetEntity="\Foo\Order\Order") * @ORM\JoinColumn(name="`order`", nullable=false) * @var \Foo\Order\Order * * @get * @set(visibility='private') */ private $order; /** * @ORM\Column(type="string", length=255) * @var string * * @get * @set(visibility='private') */ private $contactName; } ``` Loading this entity fails with error `ErrorException: Undefined index: order in...\lib\Doctrine\ORM\Utility\IdentifierFlattener.php:92`. The problem is, that data that goes to UoW::createEntity and to `flattenIdentifier` look like this ``` array (6) contactName => "j8" "`order`" => 7050473951 ``` note the backticks around order _If the `order` column was generic `@Column`, the backticks would not be there_ _If `order` was association but not an ID, the loading would not fail, but silently leave `$order = null`_ The root cause, I think, is in method BaseEntityPersister::getSelectColumnAssociationSQL, where column name added to ResultSetMapping is the quoted version for JoinColumn, but for other ordinary columns it adds non-quoted version. The quoted version is then passed from ObjectHydrator to uow::createEntity and produces the error This pull should fix the problem, although I'm not entirely sure if this is the only place with this issue.
admin added the pull-request label 2026-01-22 16:05:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9701