orphanRemoval not working for OneToMany collections when using a custom type for the identifier and oracle database #6976

Open
opened 2026-01-22 15:42:30 +01:00 by admin · 2 comments
Owner

Originally created by @lordrhodos on GitHub (May 9, 2022).

Bug Report

Q A
BC Break no
Version 2.11.3

Summary

When using a custom type for the identifier of a OneToMany relation the orphanRemoval setting will trigger an error.

Current behavior

In my case I am using a OneToMany relation to SessionTag:

Session

    /**
     * @ORM\OneToMany(
     *     targetEntity="SessionTag",
     *     mappedBy="session",
     *     fetch="EXTRA_LAZY",
     *     cascade={"remove"},
     * )
     */
    private Collection $sessionTags;

SessionTag uses a custom uuid type as id:

SessionTag

    /**
     * @ORM\Id
     * @ORM\Column(name="id", type="uuid")
     */
    private UuidInterface $id;

When I add the orphanRemoval=true attribute to the annotation and remove entities from the collection, a flush will trigger the following error:

[2022-05-09T10:35:18.563416+02:00] request.CRITICAL: Uncaught PHP Exception PHPUnit\Framework\Error\Warning: "oci_bind_by_name(): Invalid variable used for bind" at /var/www/app/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php line 86 {"exception":"[object] (PHPUnit\\Framework\\Error\\Warning(code: 2): oci_bind_by_name(): Invalid variable used for bind at /var/www/app/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php:86)"} []

Root cause

The cause of the issue is the missing support for custom types in the method \Doctrine\ORM\Persisters\Collection\OneToManyPersister::deleteEntityCollection. The executeStatement is called without passing the types, triggering the error:

4af1aa3177/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php (L169-L187)

Expected behavior

The orphanRemoval attribute should be supported for custom types.

Originally created by @lordrhodos on GitHub (May 9, 2022). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.11.3 #### Summary When using a custom type for the identifier of a `OneToMany` relation the `orphanRemoval` setting will trigger an error. #### Current behavior In my case I am using a `OneToMany` relation to `SessionTag`: **Session** ```php /** * @ORM\OneToMany( * targetEntity="SessionTag", * mappedBy="session", * fetch="EXTRA_LAZY", * cascade={"remove"}, * ) */ private Collection $sessionTags; ``` `SessionTag` uses a custom uuid type as id: **SessionTag** ```php /** * @ORM\Id * @ORM\Column(name="id", type="uuid") */ private UuidInterface $id; ``` When I add the `orphanRemoval=true` attribute to the annotation and remove entities from the collection, a `flush` will trigger the following error: [2022-05-09T10:35:18.563416+02:00] request.CRITICAL: Uncaught PHP Exception PHPUnit\Framework\Error\Warning: "oci_bind_by_name(): Invalid variable used for bind" at /var/www/app/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php line 86 {"exception":"[object] (PHPUnit\\Framework\\Error\\Warning(code: 2): oci_bind_by_name(): Invalid variable used for bind at /var/www/app/vendor/doctrine/dbal/src/Driver/OCI8/Statement.php:86)"} [] #### Root cause The cause of the issue is the missing support for custom types in the method `\Doctrine\ORM\Persisters\Collection\OneToManyPersister::deleteEntityCollection`. The `executeStatement` is called without passing the types, triggering the error: https://github.com/doctrine/orm/blob/4af1aa317713d5f3dbc57b22237d1acb8477079c/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php#L169-L187 #### Expected behavior The `orphanRemoval` attribute should be supported for custom types.
Author
Owner

@derrabus commented on GitHub (May 11, 2022):

Thank you for your report. Are you able to work on a fix?

@derrabus commented on GitHub (May 11, 2022): Thank you for your report. Are you able to work on a fix?
Author
Owner

@lordrhodos commented on GitHub (May 12, 2022):

Thank you for your report. Are you able to work on a fix?

@derrabus the fix is ready, but I had no luck providing a failing test with sqlite so far. Will work on that 😉

@lordrhodos commented on GitHub (May 12, 2022): > Thank you for your report. Are you able to work on a fix? @derrabus the fix is ready, but I had no luck providing a failing test with sqlite so far. Will work on that 😉
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6976