diff --git a/packages/store/addon/-private/system/core-store.ts b/packages/store/addon/-private/system/core-store.ts index 83fbb6666ec..590db4d4cbe 100644 --- a/packages/store/addon/-private/system/core-store.ts +++ b/packages/store/addon/-private/system/core-store.ts @@ -1632,18 +1632,7 @@ abstract class CoreStore 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) as RelationshipRecordData).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; @@ -1713,14 +1702,7 @@ abstract class CoreStore extends Service { } return this.findBelongsTo(parentInternalModel, resource.links.related, relationshipMeta, options).then( internalModel => { - let response = - internalModel && (recordDataFor(internalModel) as RelationshipRecordData).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/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index d7828926511..a5187221888 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -515,16 +515,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/finders.js b/packages/store/addon/-private/system/store/finders.js index ca693887e08..5f91898f5cd 100644 --- a/packages/store/addon/-private/system/store/finders.js +++ b/packages/store/addon/-private/system/store/finders.js @@ -130,17 +130,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) { @@ -282,10 +289,9 @@ export function _findHasMany(adapter, store, internalModel, link, relationship, let serializer = store.serializerFor(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, @@ -311,7 +317,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); },