Skip to content

Commit 747f278

Browse files
committed
Enable deleting pointer fields, fix tests
1 parent 0a0d4f6 commit 747f278

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

spec/Schema.spec.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,28 +522,31 @@ describe('Schema', () => {
522522
});
523523

524524
it('can delete string fields and resave as number field', done => {
525+
Parse.Object.disableSingleInstance();
525526
var obj1 = hasAllPODobject();
526527
var obj2 = hasAllPODobject();
527528
var p = Parse.Object.saveAll([obj1, obj2])
528529
.then(() => config.database.loadSchema())
529530
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.db, 'test_'))
530531
.then(() => new Parse.Query('HasAllPOD').get(obj1.id))
531-
.then(obj1 => {
532-
expect(obj1.get('aString')).toEqual(undefined);
533-
obj1.set('aString', ['not a string', 'this time']);
534-
obj1.save()
535-
.then(obj1 => {
536-
expect(obj1.get('aString')).toEqual(['not a string', 'this time']);
532+
.then(obj1Reloaded => {
533+
expect(obj1Reloaded.get('aString')).toEqual(undefined);
534+
obj1Reloaded.set('aString', ['not a string', 'this time']);
535+
obj1Reloaded.save()
536+
.then(obj1reloadedAgain => {
537+
expect(obj1reloadedAgain.get('aString')).toEqual(['not a string', 'this time']);
537538
return new Parse.Query('HasAllPOD').get(obj2.id);
538539
})
539-
.then(obj2 => {
540-
expect(obj2.get('aString')).toEqual(undefined);
540+
.then(obj2reloaded => {
541+
expect(obj2reloaded.get('aString')).toEqual(undefined);
541542
done();
543+
Parse.Object.enableSingleInstance();
542544
});
543545
})
544546
});
545547

546548
it('can delete pointer fields and resave as string', done => {
549+
Parse.Object.disableSingleInstance();
547550
var obj1 = new Parse.Object('NewClass');
548551
obj1.save()
549552
.then(() => {
@@ -564,6 +567,7 @@ describe('Schema', () => {
564567
.then(obj1 => {
565568
expect(obj1.get('aPointer')).toEqual('Now a string');
566569
done();
570+
Parse.Object.enableSingleInstance();
567571
});
568572
});
569573
});

src/Schema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ Schema.prototype.deleteField = function(fieldName, className, database, prefix)
471471
if (err) {
472472
reject(err);
473473
} else {
474+
var mongoFieldName = schema.data[className][fieldName].startsWith('*') ?
475+
'_p_' + fieldName :
476+
fieldName;
474477
return coll.update({}, {
475-
"$unset": { [fieldName] : null },
478+
"$unset": { [mongoFieldName] : null },
476479
}, {
477480
multi: true,
478481
})

0 commit comments

Comments
 (0)