From 2e48a8e9c411db2a816f2c05548604a66cf7d8a2 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Tue, 28 May 2024 11:04:09 -0700 Subject: [PATCH] fix: bulk saves looking at wrong metadata to determine property relational role --- .../src/components/test-setup.vue | 136 ++++++++++++++++-- .../Api/Controllers/BaseApiController.cs | 7 +- 2 files changed, 125 insertions(+), 18 deletions(-) diff --git a/playground/Coalesce.Web.Vue3/src/components/test-setup.vue b/playground/Coalesce.Web.Vue3/src/components/test-setup.vue index 0e1693f69..28c66d8f2 100644 --- a/playground/Coalesce.Web.Vue3/src/components/test-setup.vue +++ b/playground/Coalesce.Web.Vue3/src/components/test-setup.vue @@ -1,14 +1,54 @@ diff --git a/src/IntelliTect.Coalesce/Api/Controllers/BaseApiController.cs b/src/IntelliTect.Coalesce/Api/Controllers/BaseApiController.cs index 4c52b74f7..7eef53136 100644 --- a/src/IntelliTect.Coalesce/Api/Controllers/BaseApiController.cs +++ b/src/IntelliTect.Coalesce/Api/Controllers/BaseApiController.cs @@ -196,8 +196,9 @@ IBehaviorsFactory behaviorsFactory continue; } - var referencedProp = item.ParamDtoClassViewModel.PropertyByName(reference.Key); - if (referencedProp is not { Role: PropertyRole.ForeignKey, IsClientWritable: true }) + var referencedModelProp = item.DeclaredForClassViewModel.PropertyByName(reference.Key); + var referencedDtoProp = item.ParamDtoClassViewModel.PropertyByName(reference.Key); + if (referencedDtoProp is null || referencedModelProp is not { Role: PropertyRole.ForeignKey, IsClientWritable: true }) { // Ignore invalid refs. We only need to resolve writable foreign keys. continue; @@ -214,7 +215,7 @@ IBehaviorsFactory behaviorsFactory } // Update the DTO with the new FK. - referencedProp.PropertyInfo.SetValue(item.Data, principalKey); + referencedDtoProp.PropertyInfo.SetValue(item.Data, principalKey); } // If we made it here, there were no refs preventing a save.