#1169 DDC-3343 - adapting patch to 2.4 branch
This commit is contained in:
parent
daca81861c
commit
c4b59b4eb0
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Persisters;
|
namespace Doctrine\ORM\Persisters;
|
||||||
|
|
||||||
|
use Doctrine\Common\Proxy\Proxy;
|
||||||
use Doctrine\ORM\PersistentCollection;
|
use Doctrine\ORM\PersistentCollection;
|
||||||
use Doctrine\ORM\UnitOfWork;
|
use Doctrine\ORM\UnitOfWork;
|
||||||
|
|
||||||
@ -237,11 +238,20 @@ class OneToManyPersister extends AbstractCollectionPersister
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapping = $coll->getMapping();
|
$mapping = $coll->getMapping();
|
||||||
$class = $this->em->getClassMetadata($mapping['targetEntity']);
|
$persister = $this->uow->getEntityPersister($mapping['targetEntity']);
|
||||||
$sql = 'DELETE FROM ' . $this->quoteStrategy->getTableName($class, $this->platform)
|
$targetMetadata = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||||
. ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?';
|
|
||||||
|
|
||||||
return (bool) $this->conn->executeUpdate($sql, $this->getDeleteRowSQLParameters($coll, $element));
|
if ($element instanceof Proxy && ! $element->__isInitialized()) {
|
||||||
|
$element->__load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clearing owning side value
|
||||||
|
$targetMetadata->reflFields[$mapping['mappedBy']]->setValue($element, null);
|
||||||
|
|
||||||
|
$this->uow->computeChangeSet($targetMetadata, $element);
|
||||||
|
$persister->update($element);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,90 +402,6 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
|
$this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group DDC-2504
|
|
||||||
*/
|
|
||||||
public function testRemovalOfManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt()
|
|
||||||
{
|
|
||||||
$otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
|
|
||||||
$childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId);
|
|
||||||
|
|
||||||
$queryCount = $this->getCurrentQueryCount();
|
|
||||||
|
|
||||||
$otherClass->childClasses->removeElement($childClass);
|
|
||||||
|
|
||||||
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$queryCount + 1,
|
|
||||||
$this->getCurrentQueryCount(),
|
|
||||||
'The owning side of the association is updated'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertFalse($otherClass->childClasses->contains($childClass));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group DDC-2504
|
|
||||||
*/
|
|
||||||
public function testRemovalOfNonManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt()
|
|
||||||
{
|
|
||||||
$otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
|
|
||||||
$queryCount = $this->getCurrentQueryCount();
|
|
||||||
|
|
||||||
$otherClass->childClasses->removeElement(new DDC2504ChildClass());
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$queryCount,
|
|
||||||
$this->getCurrentQueryCount(),
|
|
||||||
'Removing an unmanaged entity should cause no query to be executed.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group DDC-2504
|
|
||||||
*/
|
|
||||||
public function testRemovalOfNewElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt()
|
|
||||||
{
|
|
||||||
$otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
|
|
||||||
$childClass = new DDC2504ChildClass();
|
|
||||||
|
|
||||||
$this->_em->persist($childClass);
|
|
||||||
|
|
||||||
$queryCount = $this->getCurrentQueryCount();
|
|
||||||
|
|
||||||
$otherClass->childClasses->removeElement($childClass);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$queryCount,
|
|
||||||
$this->getCurrentQueryCount(),
|
|
||||||
'Removing a new entity should cause no query to be executed.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group DDC-2504
|
|
||||||
*/
|
|
||||||
public function testRemovalOfNewManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt()
|
|
||||||
{
|
|
||||||
$otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
|
|
||||||
$childClass = new DDC2504ChildClass();
|
|
||||||
|
|
||||||
$this->_em->persist($childClass);
|
|
||||||
$this->_em->flush();
|
|
||||||
|
|
||||||
$queryCount = $this->getCurrentQueryCount();
|
|
||||||
|
|
||||||
$otherClass->childClasses->removeElement($childClass);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
$queryCount,
|
|
||||||
$this->getCurrentQueryCount(),
|
|
||||||
'No queries are executed, as the owning side of the association is not actually updated.'
|
|
||||||
);
|
|
||||||
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType;
|
|||||||
|
|
||||||
use Doctrine\Tests\Models\Tweet\Tweet;
|
use Doctrine\Tests\Models\Tweet\Tweet;
|
||||||
use Doctrine\Tests\Models\Tweet\User;
|
use Doctrine\Tests\Models\Tweet\User;
|
||||||
use Doctrine\Tests\Models\ValueConversionType as Entity;
|
|
||||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,89 +20,8 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->useModelSet('tweet');
|
$this->useModelSet('tweet');
|
||||||
$this->useModelSet('vct_onetomany_extralazy');
|
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$inversed = new Entity\InversedOneToManyExtraLazyEntity();
|
|
||||||
$inversed->id1 = 'abc';
|
|
||||||
|
|
||||||
$owning1 = new Entity\OwningManyToOneExtraLazyEntity();
|
|
||||||
$owning1->id2 = 'def';
|
|
||||||
|
|
||||||
$owning2 = new Entity\OwningManyToOneExtraLazyEntity();
|
|
||||||
$owning2->id2 = 'ghi';
|
|
||||||
|
|
||||||
$owning3 = new Entity\OwningManyToOneExtraLazyEntity();
|
|
||||||
$owning3->id2 = 'jkl';
|
|
||||||
|
|
||||||
$inversed->associatedEntities->add($owning1);
|
|
||||||
$owning1->associatedEntity = $inversed;
|
|
||||||
$inversed->associatedEntities->add($owning2);
|
|
||||||
$owning2->associatedEntity = $inversed;
|
|
||||||
$inversed->associatedEntities->add($owning3);
|
|
||||||
$owning3->associatedEntity = $inversed;
|
|
||||||
|
|
||||||
$this->_em->persist($inversed);
|
|
||||||
$this->_em->persist($owning1);
|
|
||||||
$this->_em->persist($owning2);
|
|
||||||
$this->_em->persist($owning3);
|
|
||||||
|
|
||||||
$this->_em->flush();
|
|
||||||
$this->_em->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function tearDownAfterClass()
|
|
||||||
{
|
|
||||||
$conn = static::$_sharedConn;
|
|
||||||
|
|
||||||
$conn->executeUpdate('DROP TABLE vct_owning_manytoone_extralazy');
|
|
||||||
$conn->executeUpdate('DROP TABLE vct_inversed_onetomany_extralazy');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThatExtraLazyCollectionIsCounted()
|
|
||||||
{
|
|
||||||
$inversed = $this->_em->find(
|
|
||||||
'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity',
|
|
||||||
'abc'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(3, $inversed->associatedEntities->count());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThatExtraLazyCollectionContainsAnEntity()
|
|
||||||
{
|
|
||||||
$inversed = $this->_em->find(
|
|
||||||
'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity',
|
|
||||||
'abc'
|
|
||||||
);
|
|
||||||
|
|
||||||
$owning = $this->_em->find(
|
|
||||||
'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity',
|
|
||||||
'def'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertTrue($inversed->associatedEntities->contains($owning));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThatExtraLazyCollectionContainsAnIndexbyKey()
|
|
||||||
{
|
|
||||||
$inversed = $this->_em->find(
|
|
||||||
'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity',
|
|
||||||
'abc'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertTrue($inversed->associatedEntities->containsKey('def'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThatASliceOfTheExtraLazyCollectionIsLoaded()
|
|
||||||
{
|
|
||||||
$inversed = $this->_em->find(
|
|
||||||
'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity',
|
|
||||||
'abc'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(2, $inversed->associatedEntities->slice(0, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,6 +139,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
'Doctrine\Tests\Models\StockExchange\Stock',
|
'Doctrine\Tests\Models\StockExchange\Stock',
|
||||||
'Doctrine\Tests\Models\StockExchange\Market',
|
'Doctrine\Tests\Models\StockExchange\Market',
|
||||||
),
|
),
|
||||||
|
'tweet' => array(
|
||||||
|
'Doctrine\Tests\Models\Tweet\Tweet',
|
||||||
|
'Doctrine\Tests\Models\Tweet\User',
|
||||||
|
),
|
||||||
'legacy' => array(
|
'legacy' => array(
|
||||||
'Doctrine\Tests\Models\Legacy\LegacyUser',
|
'Doctrine\Tests\Models\Legacy\LegacyUser',
|
||||||
'Doctrine\Tests\Models\Legacy\LegacyUserReference',
|
'Doctrine\Tests\Models\Legacy\LegacyUserReference',
|
||||||
@ -269,6 +273,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
$conn->executeUpdate('DELETE FROM exchange_stocks');
|
$conn->executeUpdate('DELETE FROM exchange_stocks');
|
||||||
$conn->executeUpdate('DELETE FROM exchange_markets');
|
$conn->executeUpdate('DELETE FROM exchange_markets');
|
||||||
}
|
}
|
||||||
|
if (isset($this->_usedModelSets['tweet'])) {
|
||||||
|
$conn->executeUpdate('DELETE FROM tweet_tweet');
|
||||||
|
$conn->executeUpdate('DELETE FROM tweet_user');
|
||||||
|
}
|
||||||
if (isset($this->_usedModelSets['legacy'])) {
|
if (isset($this->_usedModelSets['legacy'])) {
|
||||||
$conn->executeUpdate('DELETE FROM legacy_users_cars');
|
$conn->executeUpdate('DELETE FROM legacy_users_cars');
|
||||||
$conn->executeUpdate('DELETE FROM legacy_users_reference');
|
$conn->executeUpdate('DELETE FROM legacy_users_reference');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user