Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fred-jan opened this issue Aug 23, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@fred-jan
Copy link

fred-jan commented Aug 23, 2016

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);
        }
        // ...
@fred-jan fred-jan changed the title JoinedSubclassPersister::delete does not pass $types argument to the connection JoinedSubclassPersister::delete does not pass $types argument to Connection::delete Aug 23, 2016
fred-jan added a commit to MyOnlineStore/doctrine2 that referenced this issue Aug 23, 2016
fred-jan added a commit to MyOnlineStore/doctrine2 that referenced this issue Aug 23, 2016
(cherry picked from commit 92e0e29)
@lcobucci
Copy link
Member

Handled by #7322

@lcobucci lcobucci self-assigned this Sep 20, 2019
@lcobucci lcobucci added the Bug label Sep 20, 2019
@lcobucci lcobucci added this to the 2.6.4 milestone Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants