From 47f8cce5ca5dc6534fca406777bb5acf6d122cd4 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Wed, 2 Oct 2024 13:15:30 -0600 Subject: [PATCH] fix: keep foreign keys on native platforms when they are part of the primary key --- .../appsync-modelgen-plugin/src/visitors/appsync-visitor.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index cb2cea965..7d635cbad 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -1184,7 +1184,11 @@ export class AppSyncModelVisitor< connectionInfo.targetName !== 'id' ) { // Need to remove the field that is targetName - connectionInfo.targetNames.forEach(targetName => removeFieldFromModel(model, targetName)); + // Don't remove the field if it is a primary key field + const primaryKeyFieldNames = getModelPrimaryKeyComponentFields(model).map(field => field.name); + connectionInfo.targetNames + .filter(targetName => !primaryKeyFieldNames.includes(targetName)) + .forEach(targetName => removeFieldFromModel(model, targetName)); } }); });