DDC-656: UnitOfWork::recomputeSingleEntityChangeSet does not preserve field order #809

Open
opened 2026-01-22 12:51:14 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 25, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user wizardz:

XML

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Entities\Specification" table="specification">
        <field name="name" type="string" column="name" length="255"/>
        <field name="type" type="string" column="type"/>
        <id name="specificationId" type="integer" column="specification_id">
            <generator strategy="AUTO"/>
        </id>
    </entity>
</doctrine-mapping>

Code

$spec = new \Entities\Specification();
$spec->setName('test1');
$spec->setType('type1');
$em->persist($spec);
$em->getUnitOfWork()->computeChangeSet($em->getClassMetadata(get_class($spec)), $spec);
$data1 = $em->getUnitOfWork()->getEntityChangeset($spec);
$spec->setType('type2');
$em->getUnitOfWork()->recomputeSingleEntityChangeSet($em->getClassMetadata(get_class($spec)), $spec);
$data2 = $em->getUnitOfWork()->getEntityChangeset($spec);
// data1 contains keys in correct order: name, type
var_dump($data1);
// data2 contains keys in reverse order: type, name
var_dump($data2);

I got this issue when was trying to change entity properties using onFlush event

Originally created by @doctrinebot on GitHub (Jun 25, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user wizardz: XML ``` <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Entities\Specification" table="specification"> <field name="name" type="string" column="name" length="255"/> <field name="type" type="string" column="type"/> <id name="specificationId" type="integer" column="specification_id"> <generator strategy="AUTO"/> </id> </entity> </doctrine-mapping> ``` Code ``` $spec = new \Entities\Specification(); $spec->setName('test1'); $spec->setType('type1'); $em->persist($spec); $em->getUnitOfWork()->computeChangeSet($em->getClassMetadata(get_class($spec)), $spec); $data1 = $em->getUnitOfWork()->getEntityChangeset($spec); $spec->setType('type2'); $em->getUnitOfWork()->recomputeSingleEntityChangeSet($em->getClassMetadata(get_class($spec)), $spec); $data2 = $em->getUnitOfWork()->getEntityChangeset($spec); // data1 contains keys in correct order: name, type var_dump($data1); // data2 contains keys in reverse order: type, name var_dump($data2); ``` I got this issue when was trying to change entity properties using onFlush event
admin added the Bug label 2026-01-22 12:51:14 +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#809