DDC-130 - Make self-referential relationsships work by deleting both the owning and the inverse pair of keys
This commit is contained in:
parent
b0e4d06c40
commit
ede6205204
@ -345,16 +345,30 @@ class BasicEntityPersister
|
||||
foreach ($this->_class->associationMappings AS $mapping) {
|
||||
/* @var $mapping \Doctrine\ORM\Mapping\AssociationMapping */
|
||||
if ($mapping->isManyToMany()) {
|
||||
// @Todo this only covers scenarios with no inheritance or of the same level. Is there something
|
||||
// like self-referential relationship between different levels of an inheritance hierachy? I hope not!
|
||||
$selfReferential = ($mapping->targetEntityName == $mapping->sourceEntityName);
|
||||
|
||||
if (!$mapping->isOwningSide) {
|
||||
$relatedClass = $this->_em->getClassMetadata($mapping->targetEntityName);
|
||||
$mapping = $relatedClass->associationMappings[$mapping->mappedBy];
|
||||
$keys = array_keys($mapping->relationToTargetKeyColumns);
|
||||
if ($selfReferential) {
|
||||
$otherKeys = array_keys($mapping->relationToSourceKeyColumns);
|
||||
}
|
||||
} else {
|
||||
$keys = array_keys($mapping->relationToSourceKeyColumns);
|
||||
if ($selfReferential) {
|
||||
$otherKeys = array_keys($mapping->relationToTargetKeyColumns);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$mapping->isOnDeleteCascade) {
|
||||
$this->_conn->delete($mapping->joinTable['name'], array_combine($keys, $identifier));
|
||||
|
||||
if ($selfReferential) {
|
||||
$this->_conn->delete($mapping->joinTable['name'], array_combine($otherKeys, $identifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
*/
|
||||
public function testDeleteJoinTableRecords()
|
||||
{
|
||||
$this->markTestSkipped('Nightmare! friends adds both ID 6-7 and 7-6 into two rows of the join table. How to detect this?');
|
||||
#$this->markTestSkipped('Nightmare! friends adds both ID 6-7 and 7-6 into two rows of the join table. How to detect this?');
|
||||
|
||||
$employee1 = new CompanyEmployee();
|
||||
$employee1->setName('gblanco');
|
||||
|
Loading…
x
Reference in New Issue
Block a user