forked from doctrine/orm
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDC-2996] Fix bug in UnitOfWork#recomputeSingleEntityChangeSet
When calling UnitOfWork#recomputeSingleEntityChangeSet on an entity that didn't have a changeset before, the computation was ignored. This method however is suggested to be used in "onFlush" and "preFlush" events in the documentation. Also fix a bug where recomputeSingleEntityChangeSet was used before calculating a real changeset for an object.
- Loading branch information
Showing
3 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2996Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
|
||
/** | ||
* @group DDC-2996 | ||
*/ | ||
class DDC2996Test extends \Doctrine\Tests\OrmFunctionalTestCase | ||
{ | ||
public function testIssue() | ||
{ | ||
$this->_schemaTool->createSchema(array( | ||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996User'), | ||
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2996UserPreference'), | ||
)); | ||
|
||
$pref = new DDC2996UserPreference(); | ||
$pref->user = new DDC2996User(); | ||
$pref->value = "foo"; | ||
|
||
$this->_em->persist($pref); | ||
$this->_em->persist($pref->user); | ||
$this->_em->flush(); | ||
|
||
$pref->value = "bar"; | ||
$this->_em->flush(); | ||
|
||
$this->assertEquals(1, $pref->user->counter); | ||
|
||
$this->_em->clear(); | ||
|
||
$pref = $this->_em->find(__NAMESPACE__ . '\\DDC2996UserPreference', $pref->id); | ||
$this->assertEquals(1, $pref->user->counter); | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class DDC2996User | ||
{ | ||
/** | ||
* @Id @GeneratedValue @Column(type="integer") | ||
*/ | ||
public $id; | ||
/** | ||
* @Column(type="integer") | ||
*/ | ||
public $counter = 0; | ||
} | ||
|
||
/** | ||
* @Entity @HasLifecycleCallbacks | ||
*/ | ||
class DDC2996UserPreference | ||
{ | ||
/** | ||
* @Id @GeneratedValue @Column(type="integer") | ||
*/ | ||
public $id; | ||
/** | ||
* @Column(type="string") | ||
*/ | ||
public $value; | ||
|
||
/** | ||
* @ManyToOne(targetEntity="DDC2996User") | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* @PreFlush | ||
*/ | ||
public function preFlush($event) | ||
{ | ||
$em = $event->getEntityManager(); | ||
$uow = $em->getUnitOfWork(); | ||
|
||
if ($uow->getOriginalEntityData($this->user)) { | ||
$this->user->counter++; | ||
$uow->recomputeSingleEntityChangeSet( | ||
$em->getClassMetadata(get_class($this->user)), | ||
$this->user | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters