From 34bff44eee0cebe7b49c3aa42040930795e51176 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Thu, 15 Aug 2019 22:56:39 -0700 Subject: [PATCH] [BUGFIX BETA CANARY] usage of recordDataFor for client side create needs to be in correct cache (#6334) * [BUGFIX BETA CANARY] allow creation via recordDataFor * [BUGFIX BETA CANARY] usage of recordDataFor for client side create needs to be in correct cache (cherry picked from commit 2dff02947053eb14623306ab73e02cbbf05bca43) --- packages/store/addon/-private/system/store.ts | 12 +++++++----- .../system/store/record-data-store-wrapper.ts | 9 +++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/store/addon/-private/system/store.ts b/packages/store/addon/-private/system/store.ts index 4d7e6b07843..bd173cc0fbc 100644 --- a/packages/store/addon/-private/system/store.ts +++ b/packages/store/addon/-private/system/store.ts @@ -2921,13 +2921,15 @@ class Store extends Service { } } - recordDataFor(modelName: string, id: string, clientId?: string | null): RecordData; - recordDataFor(modelName: string, id: string | null, clientId: string): RecordData; - recordDataFor(modelName: string, id: string | null, clientId?: string | null): RecordData { + recordDataFor(modelName: string, id?: string | null, clientId?: string | null): RecordData { + let internalModel: InternalModel; + if (!hasValidId(id, clientId)) { - throw new Error(`Expected either id or clientId to be valid id`); + internalModel = internalModelFactoryFor(this).build(modelName, null); + } else { + internalModel = internalModelFactoryFor(this).lookup(modelName, id, clientId); } - let internalModel = internalModelFactoryFor(this).lookup(modelName, id, clientId); + return recordDataFor(internalModel); } diff --git a/packages/store/addon/-private/system/store/record-data-store-wrapper.ts b/packages/store/addon/-private/system/store/record-data-store-wrapper.ts index de3e5f9b246..36065871923 100644 --- a/packages/store/addon/-private/system/store/record-data-store-wrapper.ts +++ b/packages/store/addon/-private/system/store/record-data-store-wrapper.ts @@ -173,13 +173,10 @@ export default class RecordDataStoreWrapper implements IRecordDataStoreWrapper { } } + recordDataFor(modelName: string, id: string, clientId?: string | null): RecordData; recordDataFor(modelName: string, id: string | null, clientId: string): RecordData; - recordDataFor(modelName: string, id: string, clientId: string | null | undefined): RecordData; - recordDataFor(modelName: string, id: string | null, clientId: string | null | undefined): RecordData { - if (!hasValidId(id, clientId)) { - throw new Error(MISSING_ID_ARG_ERROR_MESSAGE); - } - + recordDataFor(modelName: string): RecordData; + recordDataFor(modelName: string, id?: string | null, clientId?: string | null): RecordData { return this._store.recordDataFor(modelName, id, clientId); }