Skip to content

Commit

Permalink
fix: remove _refresh call from create object process
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Jan 2, 2025
1 parent 5a93ba5 commit 1fa4d73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/Persistence/PersistenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ public function refresh(object &$object, bool $force = false): object
return $object;
}

/**
* @template T of object
*
* @param T $object
*
* @return ?T
*/
public function findPersisted(object $object): ?object
{
if ($object instanceof Proxy) {
$object = unproxy($object);
}

$om = $this->strategyFor($object::class)->objectManagerFor($object::class);
$id = $om->getClassMetadata($object::class)->getIdentifierValues($object);

if (!$id) {
return null;
}

return $om->find($object::class, $id);
}

public function isPersisted(object $object): bool
{
if ($object instanceof Proxy) {
Expand Down
6 changes: 1 addition & 5 deletions src/Persistence/PersistentObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,7 @@ protected function normalizeObject(object $object): object
return $object;
}

try {
return proxy($object)->_refresh()->_real();
} catch (RefreshObjectFailed|VarExportLogicException) {
return $object;
}
return $configuration->persistence()->findPersisted($object) ?? $object;
}

final protected function isPersisting(): bool
Expand Down

0 comments on commit 1fa4d73

Please sign in to comment.