Merge branch 'DDC-2624' into 2.4
This commit is contained in:
commit
0e139055f9
@ -541,7 +541,15 @@ class UnitOfWork implements PropertyChangedListener
|
||||
foreach ($class->reflFields as $name => $refProp) {
|
||||
$value = $refProp->getValue($entity);
|
||||
|
||||
if ($class->isCollectionValuedAssociation($name) && $value !== null && ! ($value instanceof PersistentCollection)) {
|
||||
if ($class->isCollectionValuedAssociation($name) && $value !== null) {
|
||||
if ($value instanceof PersistentCollection) {
|
||||
if ($value->getOwner() === $entity) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = new ArrayCollection($value->getValues());
|
||||
}
|
||||
|
||||
// If $value is not a Collection then use an ArrayCollection.
|
||||
if ( ! $value instanceof Collection) {
|
||||
$value = new ArrayCollection($value);
|
||||
|
@ -137,6 +137,11 @@ class ECommerceProduct
|
||||
}
|
||||
}
|
||||
|
||||
public function setCategories($categories)
|
||||
{
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
@ -166,6 +171,9 @@ class ECommerceProduct
|
||||
public function __clone()
|
||||
{
|
||||
$this->isCloned = true;
|
||||
if ($this->categories) {
|
||||
$this->categories = clone $this->categories;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,12 @@ use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
||||
*/
|
||||
class DDC2074Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('ecommerce');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testShouldNotScheduleDeletionOnClonedInstances()
|
||||
{
|
||||
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct');
|
||||
@ -26,4 +32,30 @@ class DDC2074Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->assertEquals(0, count($uow->getScheduledCollectionDeletions()));
|
||||
}
|
||||
}
|
||||
|
||||
public function testSavingClonedPersistentCollection()
|
||||
{
|
||||
$product = new ECommerceProduct();
|
||||
$category = new ECommerceCategory();
|
||||
$category->setName('foo');
|
||||
$product->addCategory($category);
|
||||
|
||||
$this->_em->persist($product);
|
||||
$this->_em->persist($category);
|
||||
$this->_em->flush();
|
||||
|
||||
$newProduct = clone $product;
|
||||
|
||||
$this->_em->persist($newProduct);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$product1 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product->getId());
|
||||
$product2 = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $newProduct->getId());
|
||||
|
||||
$this->assertCount(1, $product1->getCategories());
|
||||
$this->assertCount(1, $product2->getCategories());
|
||||
|
||||
$this->assertSame($product1->getCategories()->get(0), $product2->getCategories()->get(0));
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,5 @@ class DDC2931User
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
echo 'foo';
|
||||
}
|
||||
}
|
||||
|
@ -1993,11 +1993,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
$connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SQLServerPlatform());
|
||||
$this->assertSqlGeneration(
|
||||
"SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1",
|
||||
"SELECT c0_.id AS id0 FROM cms_users c0_ WITH (NOLOCK) WHERE (c0_.name + c0_.status + 's') = ?"
|
||||
"SELECT c0_.id AS id0 FROM cms_users c0_ WHERE (c0_.name + c0_.status + 's') = ?"
|
||||
);
|
||||
$this->assertSqlGeneration(
|
||||
"SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1",
|
||||
"SELECT (c0_.id + c0_.name + c0_.status) AS sclr0 FROM cms_users c0_ WITH (NOLOCK) WHERE c0_.id = ?"
|
||||
"SELECT (c0_.id + c0_.name + c0_.status) AS sclr0 FROM cms_users c0_ WHERE c0_.id = ?"
|
||||
);
|
||||
|
||||
$connMock->setDatabasePlatform($orgPlatform);
|
||||
|
Loading…
x
Reference in New Issue
Block a user