1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Merge branch 'DDC-2624' into 2.4

This commit is contained in:
Benjamin Eberlei 2014-02-09 14:31:15 +01:00
commit 0e139055f9
5 changed files with 52 additions and 5 deletions

View File

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

View File

@ -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;
}
}
/**

View File

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

View File

@ -114,6 +114,5 @@ class DDC2931User
public function __wakeup()
{
echo 'foo';
}
}

View File

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