Skip to content

Commit

Permalink
[FEATURE ds-references] Only add function to prototype if enabled
Browse files Browse the repository at this point in the history
Currently the `referenceFor` function is added to the InternalModel's
prototype, regardless if the ds-references feature is enabled or not.
  • Loading branch information
pangratz committed Jan 7, 2016
1 parent bb36510 commit 6c1ce71
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 6c1ce71

Please sign in to comment.