Skip to content

Commit

Permalink
cleanup reference relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Aug 10, 2020
1 parent 4c68723 commit a6850fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 15 additions & 5 deletions packages/store/addon/-private/system/references/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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();
});
}
Expand Down
6 changes: 2 additions & 4 deletions packages/store/addon/-private/system/references/has-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
});
}
Expand Down

0 comments on commit a6850fb

Please sign in to comment.