From fd09178d4ed175b5294039eea722b27b0d90cb74 Mon Sep 17 00:00:00 2001 From: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Date: Mon, 22 Nov 2021 08:56:41 -0500 Subject: [PATCH] fix(@aws-amplify/datastore): belongsTo bug --- packages/datastore/src/storage/storage.ts | 27 ++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/datastore/src/storage/storage.ts b/packages/datastore/src/storage/storage.ts index 7dbb767fe39..fa33c9112db 100644 --- a/packages/datastore/src/storage/storage.ts +++ b/packages/datastore/src/storage/storage.ts @@ -28,11 +28,10 @@ import { import { Adapter } from './adapter'; import getDefaultAdapter from './adapter/getDefaultAdapter'; -export type StorageSubscriptionMessage< - T extends PersistentModel -> = SubscriptionMessage & { - mutator?: Symbol; -}; +export type StorageSubscriptionMessage = + SubscriptionMessage & { + mutator?: Symbol; + }; export type StorageFacade = Omit; export type Storage = InstanceType; @@ -135,9 +134,9 @@ class StorageClass implements StorageFacade { const element = updateMutationInput || originalElement; - const modelConstructor = (Object.getPrototypeOf( - originalElement - ) as Object).constructor as PersistentModelConstructor; + const modelConstructor = ( + Object.getPrototypeOf(originalElement) as Object + ).constructor as PersistentModelConstructor; this.pushStream.next({ model: modelConstructor, @@ -318,17 +317,15 @@ class StorageClass implements StorageFacade { const modelConstructor = Object.getPrototypeOf(model) .constructor as PersistentModelConstructor; const namespace = this.namespaceResolver(modelConstructor); - const { fields } = this.schema.namespaces[namespace].models[ - modelConstructor.name - ]; - const { primaryKey, compositeKeys = [] } = this.schema.namespaces[ - namespace - ].keys[modelConstructor.name]; + const { fields } = + this.schema.namespaces[namespace].models[modelConstructor.name]; + const { primaryKey, compositeKeys = [] } = + this.schema.namespaces[namespace].keys[modelConstructor.name]; // set original values for these fields updatedFields.forEach((field: string) => { const targetName: any = isTargetNameAssociation( - fields[field].association + fields[field]?.association ); // if field refers to a belongsTo relation, use the target field instead