DDC-2109: Duplicate joinTableColumns mapping for ManyToMany with resolve target entity #2658

Closed
opened 2026-01-22 13:59:29 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Oct 31, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user bakura:

I use the resolve target entity listener quite often for generic code. However I found an issue with ManyToMany relationships, when the target entity is modified by the listener.

The problem is that the _validateAndCompleteManyToManyMapping in PersistentCollection duplicate the joinTableColumns, so this means that when creating an entity, Doctrine send twice the number of parameters, which of course fail.

Here is a test that reproduce the problem.

public function testAssertTableColumnsAreNotAddedInManyToMany()
    {
        $evm = $this->em->getEventManager();
        $this->listener->addResolveTargetEntity(
            'Doctrine\Tests\ORM\Tools\ResolveTargetInterface',
            'Doctrine\Tests\ORM\Tools\ResolveTargetEntity',
            array()
        );
        $this->listener->addResolveTargetEntity(
            'Doctrine\Tests\ORM\Tools\TargetInterface',
            'Doctrine\Tests\ORM\Tools\TargetEntity',
            array()
        );
        $evm->addEventListener(Events::loadClassMetadata, $this->listener);
        $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity');
        $meta = $cm->associationMappings['manyToMany'];

        $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['targetEntity']);
        $this->assertEquals(array('resolvetargetentity*id', 'targetinterface*id'), $meta['joinTableColumns']);
    }
Originally created by @doctrinebot on GitHub (Oct 31, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user bakura: I use the resolve target entity listener quite often for generic code. However I found an issue with ManyToMany relationships, when the target entity is modified by the listener. The problem is that the _validateAndCompleteManyToManyMapping in PersistentCollection duplicate the joinTableColumns, so this means that when creating an entity, Doctrine send twice the number of parameters, which of course fail. Here is a test that reproduce the problem. ``` public function testAssertTableColumnsAreNotAddedInManyToMany() { $evm = $this->em->getEventManager(); $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', array() ); $this->listener->addResolveTargetEntity( 'Doctrine\Tests\ORM\Tools\TargetInterface', 'Doctrine\Tests\ORM\Tools\TargetEntity', array() ); $evm->addEventListener(Events::loadClassMetadata, $this->listener); $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity'); $meta = $cm->associationMappings['manyToMany']; $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['targetEntity']); $this->assertEquals(array('resolvetargetentity*id', 'targetinterface*id'), $meta['joinTableColumns']); } ```
admin added the Bug label 2026-01-22 13:59:29 +01:00
admin closed this issue 2026-01-22 13:59:29 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 12, 2012):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Nov 12, 2012): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2658