Get a fresh copy of the model to display after create/update to ensure consistency

This commit is contained in:
Toby Zerner 2021-09-05 17:24:27 +10:00
parent 7785241e12
commit 228ea6eacc
3 changed files with 14 additions and 0 deletions

View File

@ -308,4 +308,14 @@ trait SavesData
); );
} }
} }
/**
* Get a fresh copy of the model for display.
*/
private function freshModel(ResourceType $resourceType, $model, Context $context)
{
$id = $resourceType->getAdapter()->getId($model);
return $this->findResource($resourceType, $id, $context);
}
} }

View File

@ -56,6 +56,8 @@ class Create
run_callbacks($schema->getListeners('created'), [&$model, $context]); run_callbacks($schema->getListeners('created'), [&$model, $context]);
$model = $this->freshModel($resourceType, $model, $context);
return (new Show()) return (new Show())
->handle($context, $resourceType, $model) ->handle($context, $resourceType, $model)
->withStatus(201) ->withStatus(201)

View File

@ -53,6 +53,8 @@ class Update
run_callbacks($schema->getListeners('updated'), [&$model, $context]); run_callbacks($schema->getListeners('updated'), [&$model, $context]);
$model = $this->freshModel($resourceType, $model, $context);
return (new Show()) return (new Show())
->handle($context, $resourceType, $model); ->handle($context, $resourceType, $model);
} }