AmpersandJS / ampersand-collection

A module for handling collections of objects
MIT License
68 stars 27 forks source link

.get(id) can't find object with id 0 #49

Closed audionerd closed 9 years ago

audionerd commented 9 years ago
collection.add([
  { id: 0, value: "zero" },
  { id: 1, value: "one" }
]);

collection.get(0); // expected { id: 0, value: "zero" }, but returns `undefined`

I think this is because of the check for !query on line 162 here:

get: function (query, indexName) {
    if (!query) return;
    var index = this._indexes[indexName || this.mainIndex];
    return index[query] || index[query[this.mainIndex]] || this._indexes.cid[query] || this._indexes.cid[query.cid];
},

https://github.com/AmpersandJS/ampersand-collection/blob/780e538192af04c3f206b5a224fc846cf3e25f85/ampersand-collection.js#L162

I thought this was surprising. Is it intentional?

kamilogorek commented 9 years ago

@audionerd good catch. Fixed here https://github.com/AmpersandJS/ampersand-collection/pull/50/

lukekarrys commented 9 years ago

This has been fixed by #37