Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE ds-references] Only add function to prototype if enabled #4053

Merged
merged 1 commit into from
Jan 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};

}