Skip to content

Commit 8bb6535

Browse files
author
Arthur Cinader
committed
Allow select (keys) to be altered in triggers
Inspect the keys when a query is returned from a trigger and respect the new value.
1 parent 9abf177 commit 8bb6535

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

spec/CloudCode.spec.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,4 +1306,41 @@ describe('beforeFind hooks', () => {
13061306
done();
13071307
});
13081308
});
1309-
})
1309+
1310+
it('should alter select', (done) => {
1311+
Parse.Cloud.beforeFind('MyObject', (req) => {
1312+
req.query.select('white');
1313+
return req.query;
1314+
});
1315+
1316+
const obj0 = new Parse.Object('MyObject')
1317+
.set('white', true)
1318+
.set('black', true)
1319+
.save()
1320+
.then(() => {
1321+
new Parse.Query('MyObject')
1322+
.first()
1323+
.then(result => {
1324+
expect(result.get('white')).toBe(true);
1325+
expect(result.get('black')).toBe(undefined);
1326+
done();
1327+
});
1328+
});
1329+
});
1330+
1331+
it('should not alter select', (done) => {
1332+
const obj0 = new Parse.Object('MyObject')
1333+
.set('white', true)
1334+
.set('black', true)
1335+
.save()
1336+
.then(() => {
1337+
new Parse.Query('MyObject')
1338+
.first()
1339+
.then(result => {
1340+
expect(result.get('white')).toBe(true);
1341+
expect(result.get('black')).toBe(true);
1342+
done();
1343+
});
1344+
});
1345+
});
1346+
});

src/triggers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ export function maybeRunQueryTrigger(triggerType, className, restWhere, restOpti
288288
restOptions = restOptions || {};
289289
restOptions.include = jsonQuery.include;
290290
}
291+
if (jsonQuery.keys) {
292+
restOptions = restOptions || {};
293+
restOptions.keys = jsonQuery.keys;
294+
}
291295
return {
292296
restWhere,
293297
restOptions

0 commit comments

Comments
 (0)