Merge pull request #426 from vitorbaptista/425-fix-model-set-in-backbone-0.9.9
[#425] Fix Dataset.query() when called with Query model
This commit is contained in:
commit
54018a0ae2
@ -191,7 +191,11 @@ my.Dataset = Backbone.Model.extend({
|
||||
this.trigger('query:start');
|
||||
|
||||
if (queryObj) {
|
||||
this.queryState.set(queryObj, {silent: true});
|
||||
var attributes = queryObj;
|
||||
if (queryObj instanceof my.Query) {
|
||||
attributes = queryObj.toJSON();
|
||||
}
|
||||
this.queryState.set(attributes, {silent: true});
|
||||
}
|
||||
var actualQuery = this.queryState.toJSON();
|
||||
|
||||
|
||||
@ -177,6 +177,31 @@ test('Dataset getFieldsSummary', function () {
|
||||
});
|
||||
});
|
||||
|
||||
test('query with Query model', function () {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
records: [{country: 'UK'}, {country: 'DE'}]
|
||||
});
|
||||
var query = new recline.Model.Query();
|
||||
query.addFilter({type: 'term', field: 'country', term: 'DE'});
|
||||
|
||||
dataset.query(query).done(function (results) {
|
||||
deepEqual(results.length, 1);
|
||||
deepEqual(results.models[0].toJSON(), {country: 'DE'});
|
||||
});
|
||||
});
|
||||
|
||||
test('query with plain object', function () {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
records: [{country: 'UK'}, {country: 'DE'}]
|
||||
});
|
||||
var query = {q: 'DE'};
|
||||
|
||||
dataset.query(query).done(function (results) {
|
||||
deepEqual(results.length, 1);
|
||||
deepEqual(results.models[0].toJSON(), {country: 'DE'});
|
||||
});
|
||||
});
|
||||
|
||||
test('fetch without and with explicit fields', function () {
|
||||
var dataset = new recline.Model.Dataset({
|
||||
backend: 'csv',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user