Skip to content

Commit abb166e

Browse files
committed
Merge pull request #90 from killme2008/feature/2015.04.29
Feature/2015.04.29
2 parents 578a3fc + 20bd1cc commit abb166e

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/object.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,26 @@
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} fetchOptions Optional options to set 'keys' and
773+
* 'include' option.
774+
* @param {Object} options Optional Backbone-like options object to be
775+
* passed in to set.
772776
* @return {AV.Promise} A promise that is fulfilled when the fetch
773777
* completes.
774778
*/
775-
fetch: function(options) {
779+
fetch: function() {
780+
var options = null;
781+
var fetchOptions = {};
782+
if(arguments.length === 1) {
783+
options = arguments[0];
784+
} else if(arguments.length === 2) {
785+
fetchOptions = arguments[0];
786+
options = arguments[1];
787+
}
788+
776789
var self = this;
777-
var request = AV._request("classes", this.className, this.id, 'GET');
790+
var request = AV._request("classes", this.className, this.id, 'GET',
791+
fetchOptions);
778792
return request.then(function(response, status, xhr) {
779793
self._finishFetch(self.parse(response, status, xhr), true);
780794
return self;

lib/query.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@
387387
return this;
388388
},
389389

390+
/**
391+
* Add a constraint to the query that requires a particular
392+
* <strong>array</strong> key's length to be equal to the provided value.
393+
* @param {String} key The array key to check.
394+
* @param value The length value.
395+
* @return {AV.Query} Returns the query, so you can chain this call.
396+
*/
397+
sizeEqualTo: function(key, value) {
398+
this._addCondition(key, "$size", value);
399+
},
400+
390401
/**
391402
* Add a constraint to the query that requires a particular key's value to
392403
* be not equal to the provided value.

test/query.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ describe("Queries",function(){
141141
throw error;
142142
}
143143
});
144+
145+
146+
it("sizeEqualTo",function(done){
147+
var gameScore = new GameScore();
148+
gameScore.save({
149+
players: ["a", "b"]
150+
}).then(function() {
151+
query = new AV.Query(GameScore);
152+
query.sizeEqualTo("players", 2);
153+
query.first({
154+
success: function(object) {
155+
expect(object.get('players').size).to.be(2);
156+
done();
157+
},
158+
error: function(error) {
159+
throw error;
160+
}
161+
});
162+
});
144163
});
145164
});
146165

0 commit comments

Comments
 (0)