diff --git a/packages/store/addon/-private/system/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index 6c239c78f9e..15b08ee3fcf 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -477,16 +477,6 @@ export default class InternalModel { } } - linkWasLoadedForRelationship(key, data) { - let relationships = {}; - relationships[key] = data; - this._recordData.pushData({ - id: this.id, - type: this.modelName, - relationships, - }); - } - finishedReloading() { this.isReloading = false; if (this.hasRecord) { diff --git a/packages/store/addon/-private/system/store.ts b/packages/store/addon/-private/system/store.ts index b8f2b1a7ead..a13024d86ba 100644 --- a/packages/store/addon/-private/system/store.ts +++ b/packages/store/addon/-private/system/store.ts @@ -1401,18 +1401,7 @@ class Store extends Service { // fetch via link if (shouldFindViaLink) { - return this.findHasMany(parentInternalModel, resource.links.related, relationshipMeta, options).then( - internalModels => { - let payload: { data: any[]; meta?: any } = { - data: internalModels.map(im => recordDataFor(im).getResourceIdentifier()), - }; - if (internalModels.meta !== undefined) { - payload.meta = internalModels.meta; - } - parentInternalModel.linkWasLoadedForRelationship(relationshipMeta.key, payload); - return internalModels; - } - ); + return this.findHasMany(parentInternalModel, resource.links.related, relationshipMeta, options); } let preferLocalCache = hasAnyRelationshipData && !relationshipIsEmpty; @@ -1482,13 +1471,7 @@ class Store extends Service { } return this.findBelongsTo(parentInternalModel, resource.links.related, relationshipMeta, options).then( internalModel => { - let response = internalModel && recordDataFor(internalModel).getResourceIdentifier(); - parentInternalModel.linkWasLoadedForRelationship(relationshipMeta.key, { data: response }); - if (internalModel === null) { - return null; - } - // TODO Igor this doesn't seem like the right boundary, probably the caller method should extract the record out - return internalModel.getRecord(); + return internalModel ? internalModel.getRecord() : null; } ); } diff --git a/packages/store/addon/-private/system/store/finders.js b/packages/store/addon/-private/system/store/finders.js index c1cf86498a3..e18989befad 100644 --- a/packages/store/addon/-private/system/store/finders.js +++ b/packages/store/addon/-private/system/store/finders.js @@ -131,17 +131,24 @@ function syncRelationshipDataFromLink(store, payload, parentInternalModel, relat // now, push the left hand side (the parent record) to ensure things are in sync, since // the payload will be pushed with store._push - store.push({ - data: { - id: parentInternalModel.id, - type: parentInternalModel.modelName, - relationships: { - [relationship.key]: { - data: relationshipData, - }, + const parentPayload = { + id: parentInternalModel.id, + type: parentInternalModel.modelName, + relationships: { + [relationship.key]: { + meta: payload.meta, + links: payload.links, + data: relationshipData, }, }, - }); + }; + + if (!Array.isArray(payload.included)) { + payload.included = []; + } + payload.included.push(parentPayload); + + return payload; } function ensureRelationshipIsSetToParent(payload, parentInternalModel, store, parentRelationship, index) { @@ -283,10 +290,9 @@ export function _findHasMany(adapter, store, internalModel, link, relationship, let serializer = serializerForAdapter(store, adapter, relationship.type); let payload = normalizeResponseHelper(serializer, store, modelClass, adapterPayload, null, 'findHasMany'); - syncRelationshipDataFromLink(store, payload, internalModel, relationship); + payload = syncRelationshipDataFromLink(store, payload, internalModel, relationship); let internalModelArray = store._push(payload); - internalModelArray.meta = payload.meta; return internalModelArray; }, null, @@ -312,7 +318,7 @@ export function _findBelongsTo(adapter, store, internalModel, link, relationship return null; } - syncRelationshipDataFromLink(store, payload, internalModel, relationship); + payload = syncRelationshipDataFromLink(store, payload, internalModel, relationship); return store._push(payload); },