fix delete join table not owning side
This commit is contained in:
parent
ad380e3ac6
commit
7807d6806c
@ -420,11 +420,16 @@ class BasicEntityPersister
|
|||||||
// @Todo this only covers scenarios with no inheritance or of the same level. Is there something
|
// @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!
|
// like self-referential relationship between different levels of an inheritance hierachy? I hope not!
|
||||||
$selfReferential = ($mapping['targetEntity'] == $mapping['sourceEntity']);
|
$selfReferential = ($mapping['targetEntity'] == $mapping['sourceEntity']);
|
||||||
|
$otherKeys = array();
|
||||||
|
$keys = array();
|
||||||
|
|
||||||
if ( ! $mapping['isOwningSide']) {
|
if ( ! $mapping['isOwningSide']) {
|
||||||
$relatedClass = $this->_em->getClassMetadata($mapping['targetEntity']);
|
$relatedClass = $this->_em->getClassMetadata($mapping['targetEntity']);
|
||||||
$mapping = $relatedClass->associationMappings[$mapping['mappedBy']];
|
$mapping = $relatedClass->associationMappings[$mapping['mappedBy']];
|
||||||
$keys = array_keys($mapping['relationToTargetKeyColumns']);
|
|
||||||
|
foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
|
||||||
|
$keys[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $relatedClass);
|
||||||
|
}
|
||||||
|
|
||||||
if ($selfReferential) {
|
if ($selfReferential) {
|
||||||
$otherKeys = array_keys($mapping['relationToSourceKeyColumns']);
|
$otherKeys = array_keys($mapping['relationToSourceKeyColumns']);
|
||||||
@ -438,16 +443,12 @@ class BasicEntityPersister
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset($mapping['isOnDeleteCascade'])) {
|
if ( ! isset($mapping['isOnDeleteCascade'])) {
|
||||||
$this->_conn->delete(
|
|
||||||
$this->quoteStrategy->getJoinTableName($mapping, $this->_class),
|
$joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class);
|
||||||
array_combine($keys, $identifier)
|
$this->_conn->delete($joinTableName, array_combine($keys, $identifier));
|
||||||
);
|
|
||||||
|
|
||||||
if ($selfReferential) {
|
if ($selfReferential) {
|
||||||
$this->_conn->delete(
|
$this->_conn->delete($joinTableName,array_combine($otherKeys, $identifier));
|
||||||
$this->quoteStrategy->getJoinTableName($mapping, $this->_class),
|
|
||||||
array_combine($otherKeys, $identifier)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->_schemaTool->createSchema(array(
|
$this->_schemaTool->createSchema(array(
|
||||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'),
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'),
|
||||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'),
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'),
|
||||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'),
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'),
|
||||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'),
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'),
|
||||||
));
|
));
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->fail($e->getMessage());
|
$this->fail($e->getMessage());
|
||||||
@ -110,14 +110,14 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals('Bar 33', $e3->name);
|
$this->assertEquals('Bar 33', $e3->name);
|
||||||
$this->assertEquals('Foo 44', $e4->name);
|
$this->assertEquals('Foo 44', $e4->name);
|
||||||
|
|
||||||
$this->markTestIncomplete();
|
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
$this->_em->remove($e1);
|
|
||||||
$this->_em->remove($e2);
|
|
||||||
$this->_em->remove($e3);
|
|
||||||
$this->_em->remove($e4);
|
$this->_em->remove($e4);
|
||||||
|
$this->_em->remove($e3);
|
||||||
|
$this->_em->remove($e2);
|
||||||
|
$this->_em->remove($e1);
|
||||||
|
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
|
||||||
$this->assertInstanceOf(self::CLASS_NAME, $e1);
|
$this->assertInstanceOf(self::CLASS_NAME, $e1);
|
||||||
@ -125,6 +125,12 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertInstanceOf(self::CLASS_NAME, $e3);
|
$this->assertInstanceOf(self::CLASS_NAME, $e3);
|
||||||
$this->assertInstanceOf(self::CLASS_NAME, $e4);
|
$this->assertInstanceOf(self::CLASS_NAME, $e4);
|
||||||
|
|
||||||
|
// Retreave
|
||||||
|
$e1 = $this->_em->find(self::CLASS_NAME, $e1Id);
|
||||||
|
$e2 = $this->_em->find(self::CLASS_NAME, $e2Id);
|
||||||
|
$e3 = $this->_em->find(self::CLASS_NAME, $e3Id);
|
||||||
|
$e4 = $this->_em->find(self::CLASS_NAME, $e4Id);
|
||||||
|
|
||||||
$this->assertNull($e1);
|
$this->assertNull($e1);
|
||||||
$this->assertNull($e2);
|
$this->assertNull($e2);
|
||||||
$this->assertNull($e3);
|
$this->assertNull($e3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user