diff --git a/packages/store/addon/-private/system/references/belongs-to.js b/packages/store/addon/-private/system/references/belongs-to.js index dd616c3b93f..1387b5a346a 100644 --- a/packages/store/addon/-private/system/references/belongs-to.js +++ b/packages/store/addon/-private/system/references/belongs-to.js @@ -30,7 +30,7 @@ export default class BelongsToReference extends Reference { this.type = belongsToRelationship.relationshipMeta.type; if (RECORD_ARRAY_MANAGER_IDENTIFIERS) { this.parent = internalModelFactoryFor(store).peek(parentIMOrIdentifier).recordReference; - this.parentInternalModel = internalModelFactoryFor(store).peek(parentIMOrIdentifier); + this.parentIdentifier = parentIMOrIdentifier; } else { this.parent = parentIMOrIdentifier.recordReference; this.parentInternalModel = parentIMOrIdentifier; @@ -213,10 +213,9 @@ export default class BelongsToReference extends Reference { @return {Model} the record in this relationship */ value() { - let store = this.parentInternalModel.store; let resource = this._resource(); if (resource && resource.data) { - let inverseInternalModel = store._internalModelForResource(resource.data); + let inverseInternalModel = this.store._internalModelForResource(resource.data); if (inverseInternalModel && inverseInternalModel.isLoaded()) { return inverseInternalModel.getRecord(); } @@ -286,7 +285,12 @@ export default class BelongsToReference extends Reference { @return {Promise} a promise that resolves with the record in this belongs-to relationship. */ load(options) { - return this.parentInternalModel.getBelongsTo(this.key, options); + if (RECORD_ARRAY_MANAGER_IDENTIFIERS) { + let parentInternalModel = internalModelFactoryFor(this.store).peek(this.parentIdentifier); + return parentInternalModel.getBelongsTo(this.key, options); + } else { + return this.parentInternalModel.getBelongsTo(this.key, options); + } } /** @@ -338,7 +342,13 @@ export default class BelongsToReference extends Reference { @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed. */ reload(options) { - return this.parentInternalModel.reloadBelongsTo(this.key, options).then(internalModel => { + let parentInternalModel; + if (RECORD_ARRAY_MANAGER_IDENTIFIERS) { + parentInternalModel = internalModelFactoryFor(this.store).peek(this.parentIdentifier); + } else { + parentInternalModel = this.parentInternalModel; + } + return parentInternalModel.reloadBelongsTo(this.key, options).then(internalModel => { return this.value(); }); } diff --git a/packages/store/addon/-private/system/references/has-many.js b/packages/store/addon/-private/system/references/has-many.js index a995bc497e4..a834512b541 100644 --- a/packages/store/addon/-private/system/references/has-many.js +++ b/packages/store/addon/-private/system/references/has-many.js @@ -26,12 +26,11 @@ export default class HasManyReference extends Reference { this.key = key; this.hasManyRelationship = hasManyRelationship; this.type = hasManyRelationship.relationshipMeta.type; + if (RECORD_ARRAY_MANAGER_IDENTIFIERS) { this.parent = internalModelFactoryFor(store).peek(parentIMOrIdentifier).recordReference; - this.parentInternalModel = internalModelFactoryFor(store).peek(parentIMOrIdentifier); } else { this.parent = parentIMOrIdentifier.recordReference; - this.parentInternalModel = parentIMOrIdentifier; } // TODO inverse @@ -215,8 +214,7 @@ export default class HasManyReference extends Reference { //TODO Igor cleanup return members.every(recordData => { - let store = this.parentInternalModel.store; - let internalModel = store._internalModelForResource(recordData.getResourceIdentifier()); + let internalModel = this.store._internalModelForResource(recordData.getResourceIdentifier()); return internalModel.isLoaded() === true; }); }