Skip to content

Commit

Permalink
#258: Query should only return models of given type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec de Zegher committed May 5, 2020
1 parent f443afd commit 0902fad
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions addon/adapters/pouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,20 @@ export default DS.RESTAdapter.extend({
* Returns the modified selector key to comform data key
* Ex: selector: {name: 'Mario'} wil become selector: {'data.name': 'Mario'}
*/
_buildSelector: function(selector) {
var dataSelector = {};
var selectorKeys = [];

_buildSelector: function(selector, type) {
var selectorKeys = new Set();
var dataSelector = {
'_id': {
'$gt': this.db.rel.makeDocID({ type: type }),
'$lt': this.db.rel.makeDocID({ type: type, id: {} }),
},
};

for (var key in selector) {
if(selector.hasOwnProperty(key)){
selectorKeys.push(key);
}
selectorKeys.add(key);
}

selectorKeys.forEach(function(key) {
selectorKeys.forEach(function (key) {
var dataKey = this._dataKey(key);
dataSelector[dataKey] = selector[key];
}.bind(this));
Expand Down Expand Up @@ -385,7 +388,7 @@ export default DS.RESTAdapter.extend({
var db = this.get('db');

var queryParams = {
selector: this._buildSelector(query.filter)
selector: this._buildSelector(query.filter, recordTypeName)
};

if (!isEmpty(query.sort)) {
Expand Down

0 comments on commit 0902fad

Please sign in to comment.