Details
Description
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']); }
Activity
Michaël Gallego
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
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. {code:php} 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']); } {code} |
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. {code} 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']); } {code} |
Benjamin Eberlei
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 2.3.1 [ 10323 ] | |
| Resolution | Fixed [ 1 ] |