1
0
mirror of synced 2025-03-10 06:46:09 +03:00

Merge branch 'DDC-3033'

This commit is contained in:
Benjamin Eberlei 2014-03-23 12:38:06 +01:00
commit e415da7f47
3 changed files with 160 additions and 23 deletions

View File

@ -518,10 +518,8 @@ The following restrictions apply to ``prePersist``:
sequences the ID value will *NOT* be available within any sequences the ID value will *NOT* be available within any
PrePersist events. PrePersist events.
- Doctrine will not recognize changes made to relations in a prePersist - Doctrine will not recognize changes made to relations in a prePersist
event called by "reachability" through a cascade persist unless you event. This includes modifications to
use the internal ``UnitOfWork`` API. We do not recommend such collections such as additions, removals or replacement.
operations in the persistence by reachability context, so do
this at your own risk and possibly supported by unit-tests.
preRemove preRemove
~~~~~~~~~ ~~~~~~~~~

View File

@ -918,7 +918,9 @@ class UnitOfWork implements PropertyChangedListener
$actualData = array(); $actualData = array();
foreach ($class->reflFields as $name => $refProp) { foreach ($class->reflFields as $name => $refProp) {
if ( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) { if (( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity())
&& ($name !== $class->versionField)
&& ! $class->isCollectionValuedAssociation($name)) {
$actualData[$name] = $refProp->getValue($entity); $actualData[$name] = $refProp->getValue($entity);
} }
} }
@ -929,9 +931,7 @@ class UnitOfWork implements PropertyChangedListener
foreach ($actualData as $propName => $actualValue) { foreach ($actualData as $propName => $actualValue) {
$orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null; $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
if (is_object($orgValue) && $orgValue !== $actualValue) { if ($orgValue !== $actualValue) {
$changeSet[$propName] = array($orgValue, $actualValue);
} else if ($orgValue != $actualValue || ($orgValue === null ^ $actualValue === null)) {
$changeSet[$propName] = array($orgValue, $actualValue); $changeSet[$propName] = array($orgValue, $actualValue);
} }
} }

View File

@ -0,0 +1,139 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Event\LifecycleEventArgs;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-3033
*/
class DDC3033Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function testIssue()
{
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC3033Product'),
));
$user = new DDC3033User();
$user->name = "Test User";
$this->_em->persist($user);
$user2 = new DDC3033User();
$user2->name = "Test User 2";
$this->_em->persist($user2);
$product = new DDC3033Product();
$product->title = "Test product";
$product->buyers[] = $user;
$this->_em->persist($product);
$this->_em->flush();
$product->title = "Test Change title";
$product->buyers[] = $user2;
$this->_em->persist($product);
$this->_em->flush();
$expect = array(
'title' => array(
0 => 'Test product',
1 => 'Test Change title',
),
);
$this->assertEquals($expect, $product->changeSet);
}
}
/**
* @Table
* @Entity @HasLifecycleCallbacks
*/
class DDC3033Product
{
public $changeSet = array();
/**
* @var integer $id
*
* @Column(name="id", type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @var string $title
*
* @Column(name="title", type="string", length=255)
*/
public $title;
/**
* @ManyToMany(targetEntity="DDC3033User")
* @JoinTable(
* name="user_purchases_3033",
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}
* )
*/
public $buyers;
/**
* Default constructor
*/
public function __construct()
{
$this->buyers = new ArrayCollection();
}
/**
* @PreUpdate
*/
public function preUpdate(LifecycleEventArgs $eventArgs)
{
}
/**
* @PostUpdate
*/
public function postUpdate(LifecycleEventArgs $eventArgs)
{
$em = $eventArgs->getEntityManager();
$uow = $em->getUnitOfWork();
$entity = $eventArgs->getEntity();
$classMetadata = $em->getClassMetadata(get_class($entity));
$uow->computeChangeSet($classMetadata, $entity);
$this->changeSet = $uow->getEntityChangeSet($entity);
}
}
/**
* @Table
* @Entity @HasLifecycleCallbacks
*/
class DDC3033User
{
/**
* @var integer
*
* @Column(name="id", type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @var string
*
* @Column(name="title", type="string", length=255)
*/
public $name;
}