1
0
mirror of synced 2025-02-03 05:49:25 +03:00

Move final cascade-persist-checking so that it covers not just normal flushes, but also flushes where specific entities are singled out.

This commit is contained in:
Darien Hager 2015-09-30 21:04:22 -07:00 committed by Marco Pivetta
parent 17b996da8c
commit b456cffa2d
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629

View File

@ -347,6 +347,8 @@ class UnitOfWork implements PropertyChangedListener
} }
} }
$this->assertNoCascadingGaps();
if ( ! ($this->entityInsertions || if ( ! ($this->entityInsertions ||
$this->entityDeletions || $this->entityDeletions ||
$this->entityUpdates || $this->entityUpdates ||
@ -829,16 +831,6 @@ class UnitOfWork implements PropertyChangedListener
} }
} }
} }
/**
* Filter out any entities that we (successfully) managed to schedule
* for insertion.
*/
$entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions);
if(count($entitiesNeedingCascadePersist) > 0){
list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0];
throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity);
}
} }
/** /**
@ -3395,6 +3387,26 @@ class UnitOfWork implements PropertyChangedListener
return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2); return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2);
} }
/**
* Checks that there are no new entities found through non-cascade-persist
* paths which are not also scheduled for insertion through valid paths.
*
* @return void
* @throws ORMInvalidArgumentException
*/
private function assertNoCascadingGaps()
{
/**
* Filter out any entities that we (successfully) managed to schedule
* for insertion.
*/
$entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions);
if(count($entitiesNeedingCascadePersist) > 0){
list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0];
throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity);
}
}
/** /**
* @param object $entity * @param object $entity
* @param object $managedCopy * @param object $managedCopy