Skip to content
Browse files

DDC-720 - Correct mentioned issues by @asm89

  • Loading branch information...
1 parent b910a48 commit 5d3298e706b1457ca8be02469b00ef219afe84e6 @beberlei beberlei committed Oct 23, 2011
Showing with 25 additions and 12 deletions.
  1. +4 −0 lib/Doctrine/ORM/EntityManager.php
  2. +21 −12 lib/Doctrine/ORM/UnitOfWork.php
View
4 lib/Doctrine/ORM/EntityManager.php
@@ -325,6 +325,10 @@ public function createQueryBuilder()
* This effectively synchronizes the in-memory state of managed objects with the
* database.
*
+ * If an entity is explicitly passed to this method only this entity and
+ * the cascade-persist semantics + scheduled inserts/removals are synchronized.
+ *
+ * @param object $entity
* @throws Doctrine\ORM\OptimisticLockException If a version check on an entity that
* makes use of optimistic locking fails.
*/
View
33 lib/Doctrine/ORM/UnitOfWork.php
@@ -253,7 +253,9 @@ public function __construct(EntityManager $em)
* 3) All collection deletions
* 4) All collection updates
* 5) All entity deletions
- *
+ *
+ * @param object $entity
+ * @return void
*/
public function commit($entity = null)
{
@@ -352,15 +354,28 @@ public function commit($entity = null)
}
/**
- * Only flush the given entity according to a rulset that keeps the UoW consistent.
+ * Compute the changesets of all entities scheduled for insertion
+ *
+ * @return void
+ */
+ private function computeScheduleInsertsChangeSets()
+ {
+ foreach ($this->entityInsertions as $entity) {
+ $class = $this->em->getClassMetadata(get_class($entity));
+ $this->computeChangeSet($class, $entity);
+ }
+ }
+
+ /**
+ * Only flush the given entity according to a ruleset that keeps the UoW consistent.
*
* 1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
* 2. Read Only entities are skipped.
* 3. Proxies are skipped.
* 4. Only if entity is properly managed.
*
- * @param Proxy $entity
- * @return type
+ * @param object $entity
+ * @return void
*/
private function computeSingleEntityChangeSet($entity)
{
@@ -375,10 +390,7 @@ private function computeSingleEntityChangeSet($entity)
}
// Compute changes for INSERTed entities first. This must always happen even in this case.
- foreach ($this->entityInsertions as $entity) {
- $class = $this->em->getClassMetadata(get_class($entity));
- $this->computeChangeSet($class, $entity);
- }
+ $this->computeScheduleInsertsChangeSets();
if ( $class->isReadOnly ) {
return;
@@ -575,10 +587,7 @@ public function computeChangeSet(ClassMetadata $class, $entity)
public function computeChangeSets()
{
// Compute changes for INSERTed entities first. This must always happen.
- foreach ($this->entityInsertions as $entity) {
- $class = $this->em->getClassMetadata(get_class($entity));
- $this->computeChangeSet($class, $entity);
- }
+ $this->computeScheduleInsertsChangeSets();
// Compute changes for other MANAGED entities. Change tracking policies take effect here.
foreach ($this->identityMap as $className => $entities) {

0 comments on commit 5d3298e

Please sign in to comment.
Something went wrong with that request. Please try again.