[IMP] web: allow rpc options to be passed to Model.query() calls

This commit is contained in:
Frederic van der Essen 2014-08-21 15:36:56 +02:00
parent f57787e07e
commit ea7b440dc8
1 changed files with 9 additions and 6 deletions

View File

@ -73,8 +73,9 @@ instance.web.Query = instance.web.Class.extend({
}
return q;
},
_execute: function () {
_execute: function (options) {
var self = this;
options = options || {};
return instance.session.rpc('/web/dataset/search_read', {
model: this._model.name,
fields: this._fields || false,
@ -85,7 +86,7 @@ instance.web.Query = instance.web.Class.extend({
offset: this._offset,
limit: this._limit,
sort: instance.web.serialize_sort(this._order_by)
}).then(function (results) {
}, options).then(function (results) {
self._count = results.length;
return results.records;
}, null);
@ -93,11 +94,12 @@ instance.web.Query = instance.web.Class.extend({
/**
* Fetches the first record matching the query, or null
*
* @param {Object} [options] additional options for the rpc() method
* @returns {jQuery.Deferred<Object|null>}
*/
first: function () {
first: function (options) {
var self = this;
return this.clone({limit: 1})._execute().then(function (records) {
return this.clone({limit: 1})._execute(options).then(function (records) {
delete self._count;
if (records.length) { return records[0]; }
return null;
@ -106,10 +108,11 @@ instance.web.Query = instance.web.Class.extend({
/**
* Fetches all records matching the query
*
* @param {Object} [options] additional options for the rpc() method
* @returns {jQuery.Deferred<Array<>>}
*/
all: function () {
return this._execute();
all: function (options) {
return this._execute(options);
},
/**
* Fetches the number of records matching the query in the database