DDC-3785: DBAL types are ignored in the ManyToManyPersister #4637

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

Originally created by @doctrinebot on GitHub (Jun 23, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user dadamssg:

If you're using custom DBAL types for id's, they are ignored and the value object is passed directly to be bound to the query.

For example, I have an Asset that has many Attributes. My asset's id is an AssetId object. I've created a custom DBAL type for AssetId. Whenever doctrine attempts to cleanse the Asset from orphaned Attributes an exception is thrown:

bq. An exception occurred while executing 'DELETE FROM asset_attributes WHERE asset_id = ?' with params [{}]: Warning: oci_bind_by_name(): Invalid variable used for bind

The ManyToManyPersister::delete() method does not pass along any $types to the Connection::executeUpdate() method. The executeUpdate() method checks if there are types and if there are none, does not pass the params to the _bindTypedValues() method, which I think is the problem. The params(AssetId) get passed directly to the $stmt->execute($params) method call.

I believe the ManyToManyPersister::delete() method needs to look like this. This seems to work.

    /****
     * {@inheritdoc}
     */
    public function delete(PersistentCollection $collection)
    {
        $mapping = $collection->getMapping();

        if ( ! $mapping['isOwningSide']) {
            return; // ignore inverse side
        }
        $types = [];
        $class = $this->em->getClassMetadata($mapping['sourceEntity']);

        foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
            $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em);
        }

        $this->conn->executeUpdate($this->getDeleteSQL($collection), $this->getDeleteSQLParameters($collection), $types);
    }
Originally created by @doctrinebot on GitHub (Jun 23, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user dadamssg: If you're using custom DBAL types for id's, they are ignored and the value object is passed directly to be bound to the query. For example, I have an Asset that has many Attributes. My asset's id is an AssetId object. I've created a custom DBAL type for AssetId. Whenever doctrine attempts to cleanse the Asset from orphaned Attributes an exception is thrown: bq. An exception occurred while executing 'DELETE FROM asset_attributes WHERE asset_id = ?' with params [{}]: Warning: oci_bind_by_name(): Invalid variable used for bind The ManyToManyPersister::delete() method does not pass along any $types to the Connection::executeUpdate() method. The executeUpdate() method checks if there are types and if there are none, does not pass the params to the _bindTypedValues() method, which I think is the problem. The params(AssetId) get passed directly to the $stmt->execute($params) method call. I believe the ManyToManyPersister::delete() method needs to look like this. This seems to work. ``` /**** * {@inheritdoc} */ public function delete(PersistentCollection $collection) { $mapping = $collection->getMapping(); if ( ! $mapping['isOwningSide']) { return; // ignore inverse side } $types = []; $class = $this->em->getClassMetadata($mapping['sourceEntity']); foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em); } $this->conn->executeUpdate($this->getDeleteSQL($collection), $this->getDeleteSQLParameters($collection), $types); } ```
admin added the Bug label 2026-01-22 14:46:23 +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#4637