Enable deleting pointer fields, fix tests
This commit is contained in:
@@ -522,28 +522,31 @@ describe('Schema', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can delete string fields and resave as number field', done => {
|
it('can delete string fields and resave as number field', done => {
|
||||||
|
Parse.Object.disableSingleInstance();
|
||||||
var obj1 = hasAllPODobject();
|
var obj1 = hasAllPODobject();
|
||||||
var obj2 = hasAllPODobject();
|
var obj2 = hasAllPODobject();
|
||||||
var p = Parse.Object.saveAll([obj1, obj2])
|
var p = Parse.Object.saveAll([obj1, obj2])
|
||||||
.then(() => config.database.loadSchema())
|
.then(() => config.database.loadSchema())
|
||||||
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.db, 'test_'))
|
.then(schema => schema.deleteField('aString', 'HasAllPOD', config.database.db, 'test_'))
|
||||||
.then(() => new Parse.Query('HasAllPOD').get(obj1.id))
|
.then(() => new Parse.Query('HasAllPOD').get(obj1.id))
|
||||||
.then(obj1 => {
|
.then(obj1Reloaded => {
|
||||||
expect(obj1.get('aString')).toEqual(undefined);
|
expect(obj1Reloaded.get('aString')).toEqual(undefined);
|
||||||
obj1.set('aString', ['not a string', 'this time']);
|
obj1Reloaded.set('aString', ['not a string', 'this time']);
|
||||||
obj1.save()
|
obj1Reloaded.save()
|
||||||
.then(obj1 => {
|
.then(obj1reloadedAgain => {
|
||||||
expect(obj1.get('aString')).toEqual(['not a string', 'this time']);
|
expect(obj1reloadedAgain.get('aString')).toEqual(['not a string', 'this time']);
|
||||||
return new Parse.Query('HasAllPOD').get(obj2.id);
|
return new Parse.Query('HasAllPOD').get(obj2.id);
|
||||||
})
|
})
|
||||||
.then(obj2 => {
|
.then(obj2reloaded => {
|
||||||
expect(obj2.get('aString')).toEqual(undefined);
|
expect(obj2reloaded.get('aString')).toEqual(undefined);
|
||||||
done();
|
done();
|
||||||
|
Parse.Object.enableSingleInstance();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can delete pointer fields and resave as string', done => {
|
it('can delete pointer fields and resave as string', done => {
|
||||||
|
Parse.Object.disableSingleInstance();
|
||||||
var obj1 = new Parse.Object('NewClass');
|
var obj1 = new Parse.Object('NewClass');
|
||||||
obj1.save()
|
obj1.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -564,6 +567,7 @@ describe('Schema', () => {
|
|||||||
.then(obj1 => {
|
.then(obj1 => {
|
||||||
expect(obj1.get('aPointer')).toEqual('Now a string');
|
expect(obj1.get('aPointer')).toEqual('Now a string');
|
||||||
done();
|
done();
|
||||||
|
Parse.Object.enableSingleInstance();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -471,8 +471,11 @@ Schema.prototype.deleteField = function(fieldName, className, database, prefix)
|
|||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
var mongoFieldName = schema.data[className][fieldName].startsWith('*') ?
|
||||||
|
'_p_' + fieldName :
|
||||||
|
fieldName;
|
||||||
return coll.update({}, {
|
return coll.update({}, {
|
||||||
"$unset": { [fieldName] : null },
|
"$unset": { [mongoFieldName] : null },
|
||||||
}, {
|
}, {
|
||||||
multi: true,
|
multi: true,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user