Skip to content

Commit cc0039f

Browse files
authored
Merge pull request #24 from Nogrod/master
orm refetch detached entity before save
2 parents c44f276 + c58e6a3 commit cc0039f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Storage/ORMStorageAdapter.php

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ public function save(string $key, array $data, array $options = []): void
130130
//Retrieve the entity object
131131
$entity = $this->getEntityObject($entityManager, $key, $entityClass);
132132

133+
//reFetch if detached
134+
if (!$entityManager->contains($entity)) {
135+
$id = $entityManager->getClassMetadata($entityClass)->getIdentifierValues($entity);
136+
if ([] !== $id) {
137+
$entity = $entityManager->find($entityClass, $id) ?? $entity;
138+
$this->cache[$entityClass][$key] = $entity;
139+
}
140+
}
141+
133142
//Set the data
134143
$entity->setData($data);
135144

0 commit comments

Comments
 (0)