fix: usePolicy attempting to fetch policies for unsaved entity

This commit is contained in:
Tom Moor
2023-12-28 19:59:15 -05:00
parent 6f989ec327
commit 0419e7dc52

View File

@@ -18,7 +18,12 @@ export default function usePolicy(entity?: string | Model | null) {
: "";
React.useEffect(() => {
if (entity && typeof entity !== "string") {
if (
entity &&
typeof entity !== "string" &&
!entity.isNew &&
!entity.isSaving
) {
// The policy for this model is missing, reload relationships for this model.
if (!policies.get(entity.id)) {
void entity.loadRelations();