[DDC-2109] Fix bug with ResolveTargetEntityListener and ManyToMany associations.
This commit is contained in:
parent
918ea1cdd8
commit
f453d6c85b
@ -1479,6 +1479,8 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
'onDelete' => 'CASCADE'));
|
'onDelete' => 'CASCADE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mapping['joinTableColumns'] = array();
|
||||||
|
|
||||||
foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
|
foreach ($mapping['joinTable']['joinColumns'] as &$joinColumn) {
|
||||||
if (empty($joinColumn['name'])) {
|
if (empty($joinColumn['name'])) {
|
||||||
$joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']);
|
$joinColumn['name'] = $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $joinColumn['referencedColumnName']);
|
||||||
|
@ -74,6 +74,7 @@ class ResolveTargetEntityListener
|
|||||||
$newMapping = $this->resolveTargetEntities[$mapping['targetEntity']];
|
$newMapping = $this->resolveTargetEntities[$mapping['targetEntity']];
|
||||||
$newMapping = array_replace_recursive($mapping, $newMapping);
|
$newMapping = array_replace_recursive($mapping, $newMapping);
|
||||||
$newMapping['fieldName'] = $mapping['fieldName'];
|
$newMapping['fieldName'] = $mapping['fieldName'];
|
||||||
|
|
||||||
unset($classMetadata->associationMappings[$mapping['fieldName']]);
|
unset($classMetadata->associationMappings[$mapping['fieldName']]);
|
||||||
|
|
||||||
switch ($mapping['type']) {
|
switch ($mapping['type']) {
|
||||||
|
@ -60,6 +60,31 @@ class ResolveTargetEntityListenerTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['oneToMany']['targetEntity']);
|
$this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['oneToMany']['targetEntity']);
|
||||||
$this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['oneToOne']['targetEntity']);
|
$this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['oneToOne']['targetEntity']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-2109
|
||||||
|
*/
|
||||||
|
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']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResolveTargetInterface
|
interface ResolveTargetInterface
|
||||||
|
Loading…
Reference in New Issue
Block a user