Skip to content

Commit

Permalink
switch the names of the properties on a record proxy to avoid collisi…
Browse files Browse the repository at this point in the history
…ons with defined values. fixes #56
  • Loading branch information
benkiefer committed Jun 15, 2016
1 parent 6d4e488 commit 93b1031
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
12 changes: 6 additions & 6 deletions addon/models/record-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import getOwner from 'ember-getowner-polyfill';
const { computed } = Ember;

export default Ember.ObjectProxy.extend({
source: null,
store: null,
type: null,
_source: null,
_store: null,
_type: null,

content: computed("source.[]", function() {
content: computed("_source.[]", function() {
return this.compute();
}),

init() {
this._super(...arguments);
const store = this.get('store');
const type = this.get('type');
const store = this.get('_store');
const type = this.get('_type');

var model = getOwner(store).lookup(`model:${type}`);

Expand Down
20 changes: 10 additions & 10 deletions addon/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ var Store = ServiceType.extend({
},
findOne(type) {
return RecordProxy.create({
store: this,
type: type,
source: this._findAll(type),
_store: this,
_type: type,
_source: this._findAll(type),
compute() {
return this.get("source").objectAt(0);
return this.get("_source").objectAt(0);
}
});
},
Expand Down Expand Up @@ -202,13 +202,13 @@ var Store = ServiceType.extend({
var primaryKey = primaryKeyForType(type, this);

return RecordProxy.create({
store: this,
type: type,
filter_value: actualId,
source: this._findAll(type),
_store: this,
_type: type,
_filter_value: actualId,
_source: this._findAll(type),
compute() {
var filter_value = this.get("filter_value");
return this.get("source").findBy(primaryKey, filter_value);
var filter_value = this.get("_filter_value");
return this.get("_source").findBy(primaryKey, filter_value);
}
});
}
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ test("find with filter should return array of models filtered by value", functio
assert.equal(store.find("person").get("length"), 5);
});

test("find with filter does not trump type property of object", function(assert) {
store.push("person", {
id: 9,
firstName: "Jarrod",
lastName: "Taylor",
source: "Jarrod's Mom",
store: "Walmart",
type: "developer"
});


var found = store.find("person", 9);
assert.equal(found.get("type"), "developer");
assert.equal(found.get("store"), "Walmart");
assert.equal(found.get("source"), "Jarrod's Mom");
});

test("find with filter should return array of models that tracks changes without asking for an update", function(assert) {
store.push("person", {
id: 9,
Expand Down

0 comments on commit 93b1031

Please sign in to comment.