Backups and change detection¶
backup() clones an entity and stores the clone internally by default.
$user = $userManager->findOneBy(['id' => 42]);
$user->backup();
$user->setUsername('new-name');
if ($user->modifiedSinceBackup()) {
$user->persist();
}
Retrieve the stored backup:
Create a clone without replacing the stored backup:
Manually set one:
Change detection compares serialized entity values. Call backup() before editing; modifiedSinceBackup() throws when no backup exists.
Primary-key snapshots are managed separately by setOriginalPrimaryKeys() and are used by persistence when a loaded entity key changes.