Skip to content

Commit

Permalink
Merge pull request #4053 from pangratz/fix-references-feature-for-int…
Browse files Browse the repository at this point in the history
…ernal-model

[FEATURE ds-references] Only add function to prototype if enabled
  • Loading branch information
bmac committed Jan 9, 2016
2 parents 65d1e76 + 6c1ce71 commit 9255531
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RootState from "ember-data/-private/system/model/states";
import Relationships from "ember-data/-private/system/relationships/state/create";
import Snapshot from "ember-data/-private/system/snapshot";
import EmptyObject from "ember-data/-private/system/empty-object";
import isEnabled from "ember-data/-private/features";

import {
getOwner
Expand Down Expand Up @@ -607,25 +608,6 @@ InternalModel.prototype = {
return value;
},

referenceFor: function(type, name) {
var reference = this.references[name];

if (!reference) {
var relationship = this._relationships.get(name);

if (type === "belongsTo") {
reference = new BelongsToReference(this.store, this, relationship);
} else if (type === "hasMany") {
reference = new HasManyReference(this.store, this, relationship);
}

this.references[name] = reference;
}

return reference;
},


/**
@method updateRecordArrays
@private
Expand Down Expand Up @@ -850,3 +832,25 @@ InternalModel.prototype = {
}
}
};

if (isEnabled('ds-references')) {

InternalModel.prototype.referenceFor = function(type, name) {
var reference = this.references[name];

if (!reference) {
var relationship = this._relationships.get(name);

if (type === "belongsTo") {
reference = new BelongsToReference(this.store, this, relationship);
} else if (type === "hasMany") {
reference = new HasManyReference(this.store, this, relationship);
}

this.references[name] = reference;
}

return reference;
};

}

0 comments on commit 9255531

Please sign in to comment.