#12352·orm

Entity references break change computing

Author: kira0269Created Jan 22, 2026Updated Jul 17, 2026

Bug Report

Q A
Version 3.6.0
Previous Version if the bug is a regression -

Summary

Unexpected behavior when manipulating an entity reference.

Current behavior

I get a reference of my entity with $entity = $entityManager->getReference(MyEntity::class, $id). Then I remove an existing OneToOne relation: $entity->entityB = null. This relation is configured to remove the orphan entity. When I flush ($entityManager->flush()), nothing happens.

Expected behavior

When I flush, I expect the UnitOfWork to compute the change and trigger a DELETE query on the entityB.

How to reproduce

php
#[ORM\Entity]
class EntityA
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    public ?int $id = null;

    #[ORM\OneToOne(orphanRemoval: true)]
    public ?EntityB $entityB = null
}

#[ORM\Entity]
class EntityB
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    public ?int $id = null;
}
php
/** @var EntityManagerInterface $em */
$entityA = new EntityA();
$entityB = new EntityB();
$entityA->entityB = $entityB;
$em->persist($entityA);
$em->persist($entityB);
$em->flush();

$id = $entityA->id;

$em->clear();
unset($entityA, $entityB);

$entityA = $em->getReference(EntityA, $id);
$entityA->entityB = null;
$em->flush();

Some clues

I found that in the unit of work, the attribute originalEntityData is used to compute changes. If my entity is fetched with the classic getRepository(...)->find(...), this array contains the values for the fetched entity. But if I use getReference(...), then load data by calling some attribute of it, data are loaded in my entity but the entry in originalEntityData for this entity is an empty array.