Skip to content

Commit 429f886

Browse files
author
Claire Neveu
committed
Allow creation of indexes on default fields
1 parent b1017ac commit 429f886

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

spec/schemas.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,41 @@ describe('schemas', () => {
18521852
})
18531853
});
18541854

1855+
it('can create index on default field', done => {
1856+
request.post({
1857+
url: 'http://localhost:8378/1/schemas/NewClass',
1858+
headers: masterKeyHeaders,
1859+
json: true,
1860+
body: {},
1861+
}, () => {
1862+
request.put({
1863+
url: 'http://localhost:8378/1/schemas/NewClass',
1864+
headers: masterKeyHeaders,
1865+
json: true,
1866+
body: {
1867+
indexes: {
1868+
name1: { createdAt: 1},
1869+
}
1870+
}
1871+
}, (error, response, body) => {
1872+
expect(body).toEqual({
1873+
className: 'NewClass',
1874+
fields: {
1875+
ACL: {type: 'ACL'},
1876+
createdAt: {type: 'Date'},
1877+
updatedAt: {type: 'Date'},
1878+
objectId: {type: 'String'}
1879+
},
1880+
classLevelPermissions: defaultClassLevelPermissions,
1881+
indexes: {
1882+
name1: { createdAt: 1},
1883+
},
1884+
});
1885+
done();
1886+
});
1887+
})
1888+
});
1889+
18551890
it('cannot create compound index if field does not exist', done => {
18561891
request.post({
18571892
url: 'http://localhost:8378/1/schemas/NewClass',

src/Controllers/SchemaController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ export default class SchemaController {
530530
delete existingFields._rperm;
531531
delete existingFields._wperm;
532532
const newSchema = buildMergedSchemaObject(existingFields, submittedFields);
533+
const defaultFields = defaultColumns[className] || defaultColumns._Default;
534+
const fullNewSchema = Object.assign({}, newSchema, defaultFields);
533535
const validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
534536
if (validationError) {
535537
throw new Parse.Error(validationError.code, validationError.error);
@@ -561,7 +563,7 @@ export default class SchemaController {
561563
return Promise.all(promises);
562564
})
563565
.then(() => this.setPermissions(className, classLevelPermissions, newSchema))
564-
.then(() => this._dbAdapter.setIndexesWithSchemaFormat(className, indexes, schema.indexes, newSchema))
566+
.then(() => this._dbAdapter.setIndexesWithSchemaFormat(className, indexes, schema.indexes, fullNewSchema))
565567
.then(() => this.reloadData({ clearCache: true }))
566568
//TODO: Move this logic into the database adapter
567569
.then(() => {

0 commit comments

Comments
 (0)