JoinedSubclassPersister::delete does not pass $types argument to Connection::delete #5227

Closed
opened 2026-01-22 15:02:01 +01:00 by admin · 1 comment
Owner

Originally created by @fred-jan on GitHub (Aug 23, 2016).

Originally assigned to: @lcobucci on GitHub.

My entity uses both class table inheritance and a custom id type (uuid_binary type provided by the ramsey/uuid-doctrine package). Simplified example:

/**
 * @ORM\Entity
 * @ORM\Table(name="my_entity")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap({
 *     "a" = "MyEntityA",
 *     "b" = "MyEntityB"
 * })
 */
abstract class MyEntity
{
    /**
     * @ORM\Id
     * @ORM\Column(type="uuid_binary")
     * @ORM\GeneratedValue(strategy="NONE")
     *
     * @var UuidInterface
     */
    private $id;
}

When I attempt to delete such an entity using the EntityManager, the JoinedSubclassPersister class is leveraged internally to perform the deletion and calls Connection::delete without passing along any field-mapping information as $types argument. This results in the following query being executed:

DELETE FROM my_entity WHERE id = 'Object(Ramsey\\Uuid\\Uuid)';

For my specific platform (which supports FK's) I've made a temporary fix by copying the $types assignment code from the BasicEntityPersister class, which looks like this:

        // ...
        // If the database platform supports FKs, just
        // delete the row from the root table. Cascades do the rest.
        if ($this->platform->supportsForeignKeyConstraints()) {
            $rootClass  = $this->em->getClassMetadata($this->class->rootEntityName);
            $rootTable  = $this->quoteStrategy->getTableName($rootClass, $this->platform);
            $types      = array_map(function ($identifier) use ($rootClass) {
                if (isset($rootClass->fieldMappings[$identifier])) {
                    return $rootClass->fieldMappings[$identifier]['type'];
                }

                $targetMapping = $this->em->getClassMetadata($rootClass->associationMappings[$identifier]['targetEntity']);

                if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) {
                    return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
                }

                if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) {
                    return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type'];
                }

                throw ORMException::unrecognizedField($targetMapping->identifier[0]);

            }, $rootClass->identifier);

            return (bool) $this->conn->delete($rootTable, $id, $types);
        }
        // ...
Originally created by @fred-jan on GitHub (Aug 23, 2016). Originally assigned to: @lcobucci on GitHub. My entity uses both class table inheritance and a custom id type (`uuid_binary` type provided by the `ramsey/uuid-doctrine` package). Simplified example: ``` /** * @ORM\Entity * @ORM\Table(name="my_entity") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap({ * "a" = "MyEntityA", * "b" = "MyEntityB" * }) */ abstract class MyEntity { /** * @ORM\Id * @ORM\Column(type="uuid_binary") * @ORM\GeneratedValue(strategy="NONE") * * @var UuidInterface */ private $id; } ``` When I attempt to delete such an entity using the `EntityManager`, the `JoinedSubclassPersister` class is leveraged internally to perform the deletion and calls `Connection::delete` without passing along any field-mapping information as `$types` argument. This results in the following query being executed: ``` DELETE FROM my_entity WHERE id = 'Object(Ramsey\\Uuid\\Uuid)'; ``` For my specific platform (which supports FK's) I've made a temporary fix by copying the `$types` assignment code from the `BasicEntityPersister` class, which looks like this: ``` // ... // If the database platform supports FKs, just // delete the row from the root table. Cascades do the rest. if ($this->platform->supportsForeignKeyConstraints()) { $rootClass = $this->em->getClassMetadata($this->class->rootEntityName); $rootTable = $this->quoteStrategy->getTableName($rootClass, $this->platform); $types = array_map(function ($identifier) use ($rootClass) { if (isset($rootClass->fieldMappings[$identifier])) { return $rootClass->fieldMappings[$identifier]['type']; } $targetMapping = $this->em->getClassMetadata($rootClass->associationMappings[$identifier]['targetEntity']); if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; } if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) { return $targetMapping->associationMappings[$targetMapping->identifier[0]]['type']; } throw ORMException::unrecognizedField($targetMapping->identifier[0]); }, $rootClass->identifier); return (bool) $this->conn->delete($rootTable, $id, $types); } // ... ```
admin added the Bug label 2026-01-22 15:02:01 +01:00
admin closed this issue 2026-01-22 15:02:01 +01:00
Author
Owner

@lcobucci commented on GitHub (Sep 20, 2019):

Handled by https://github.com/doctrine/orm/pull/7322

@lcobucci commented on GitHub (Sep 20, 2019): Handled by https://github.com/doctrine/orm/pull/7322
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5227