Skip to content

Commit b5a0650

Browse files
committed
Supports include and keys in AV.Object#fetch
1 parent 3556aec commit b5a0650

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/object.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,30 @@
769769
* Fetch the model from the server. If the server's representation of the
770770
* model differs from its current attributes, they will be overriden,
771771
* triggering a <code>"change"</code> event.
772+
* @param {Object} options Optional Backbone-like options object to be
773+
* passed in to set. Also you can set 'keys' and 'include' options.
772774
* @return {AV.Promise} A promise that is fulfilled when the fetch
773775
* completes.
774776
*/
775777
fetch: function(options) {
778+
var include = null;
779+
var keys = null;
780+
if(options) {
781+
var processOpt = function(k) {
782+
if(options[k]){
783+
if(_.isArray(options[k])) {
784+
return options[k].join(',');
785+
} else {
786+
return options[k];
787+
}
788+
}
789+
};
790+
include = processOpt('include');
791+
keys = processOpt('keys');
792+
}
776793
var self = this;
777-
var request = AV._request("classes", this.className, this.id, 'GET');
794+
var request = AV._request("classes", this.className, this.id, 'GET',
795+
{ include: include, keys: keys});
778796
return request.then(function(response, status, xhr) {
779797
self._finishFetch(self.parse(response, status, xhr), true);
780798
return self;

0 commit comments

Comments
 (0)