Skip to content

Commit 98c102f

Browse files
authored
fix(Query): handle multiple params for #select and #include (#386)
* fix(Query): handle multiple params for #select and #include * fix(Query): replace Array.from with underscore wrapper
1 parent d61b71c commit 98c102f

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

src/query.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ module.exports = function(AV) {
820820
*/
821821
include: function(keys) {
822822
requires(keys, 'undefined is not a valid key');
823-
this._include = this._include.concat(ensureArray(keys));
823+
_(arguments).forEach(keys => {
824+
this._include = this._include.concat(ensureArray(keys))
825+
});
824826
return this;
825827
},
826828

@@ -833,7 +835,9 @@ module.exports = function(AV) {
833835
*/
834836
select: function(keys) {
835837
requires(keys, 'undefined is not a valid key');
836-
this._select = this._select.concat(ensureArray(keys));
838+
_(arguments).forEach(keys => {
839+
this._select = this._select.concat(ensureArray(keys));
840+
});
837841
return this;
838842
},
839843

test/query.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ describe('Queries', function () {
117117
before(function() {
118118
return new GameScore({
119119
playerName: 'testname',
120+
score: 1000,
121+
players: ['a', 'b'],
122+
test: new TestClass({ foo: 'bar' }),
120123
}).save().then(gameScore => this.gameScore = gameScore);
121124
});
122125

@@ -142,17 +145,55 @@ describe('Queries', function () {
142145

143146
it('sizeEqualTo', function () {
144147
var gameScore = new GameScore();
145-
return gameScore.save({
146-
players: ['a', 'b']
147-
}).then(function () {
148-
query = new AV.Query(GameScore);
149-
query.sizeEqualTo('players', 2);
150-
return query.first();
151-
}).then(function (object) {
148+
var query = new AV.Query(GameScore);
149+
query.sizeEqualTo('players', 2);
150+
return query.first().then(function (object) {
152151
expect(object.get('players').length).to.be(2);
153152
return gameScore.destroy();
154153
});
155154
});
155+
156+
it('select with multi params', function() {
157+
return new AV.Query(GameScore)
158+
.select('test', 'score')
159+
.equalTo('objectId', this.gameScore.id)
160+
.find()
161+
.then(([gameScore]) => {
162+
expect(gameScore.get('score')).to.be(1000);
163+
expect(gameScore.get('playerName')).to.be(undefined);
164+
});
165+
});
166+
167+
it('select', function() {
168+
return new AV.Query(GameScore)
169+
.select(['test', 'score'])
170+
.equalTo('objectId', this.gameScore.id)
171+
.find()
172+
.then(([gameScore]) => {
173+
expect(gameScore.get('score')).to.be(1000);
174+
expect(gameScore.get('playerName')).to.be(undefined);
175+
});
176+
});
177+
178+
it('include with multi params', function() {
179+
return new AV.Query(GameScore)
180+
.include('score', 'test')
181+
.equalTo('objectId', this.gameScore.id)
182+
.find()
183+
.then(([gameScore]) => {
184+
expect(gameScore.get('test').get('foo')).to.be('bar');
185+
});
186+
});
187+
188+
it('include', function() {
189+
return new AV.Query(GameScore)
190+
.include(['score', 'test'])
191+
.equalTo('objectId', this.gameScore.id)
192+
.find()
193+
.then(([gameScore]) => {
194+
expect(gameScore.get('test').get('foo')).to.be('bar');
195+
});
196+
});
156197
});
157198

158199
describe('Query with different condtions', function () {

0 commit comments

Comments
 (0)