1
0
mirror of synced 2025-02-01 04:51:45 +03:00

DDC-130 - Make self-referential relationsships work by deleting both the owning and the inverse pair of keys

This commit is contained in:
Benjamin Eberlei 2010-07-10 13:35:58 +02:00
parent b0e4d06c40
commit ede6205204
2 changed files with 15 additions and 1 deletions

View File

@ -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));
}
}
}
}

View File

@ -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');