Fix delete relation field when _Join collection not exist
This commit is contained in:
@@ -577,6 +577,38 @@ describe('Schema', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can delete relation field when related _Join collection not exist', done => {
|
||||||
|
config.database.loadSchema()
|
||||||
|
.then(schema => {
|
||||||
|
schema.addClassIfNotExists('NewClass', {
|
||||||
|
relationField: {type: 'Relation', targetClass: '_User'}
|
||||||
|
})
|
||||||
|
.then(mongoObj => {
|
||||||
|
expect(mongoObj).toEqual({
|
||||||
|
_id: 'NewClass',
|
||||||
|
objectId: 'string',
|
||||||
|
updatedAt: 'string',
|
||||||
|
createdAt: 'string',
|
||||||
|
relationField: 'relation<_User>',
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => config.database.collectionExists('_Join:relationField:NewClass'))
|
||||||
|
.then(exist => {
|
||||||
|
expect(exist).toEqual(false);
|
||||||
|
})
|
||||||
|
.then(() => schema.deleteField('relationField', 'NewClass', config.database))
|
||||||
|
.then(() => schema.reloadData())
|
||||||
|
.then(() => {
|
||||||
|
expect(schema['data']['NewClass']).toEqual({
|
||||||
|
objectId: 'string',
|
||||||
|
updatedAt: 'string',
|
||||||
|
createdAt: 'string'
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
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();
|
Parse.Object.disableSingleInstance();
|
||||||
var obj1 = hasAllPODobject();
|
var obj1 = hasAllPODobject();
|
||||||
|
|||||||
@@ -409,7 +409,11 @@ class Schema {
|
|||||||
|
|
||||||
if (this.data[className][fieldName].startsWith('relation<')) {
|
if (this.data[className][fieldName].startsWith('relation<')) {
|
||||||
//For relations, drop the _Join table
|
//For relations, drop the _Join table
|
||||||
return database.dropCollection(`_Join:${fieldName}:${className}`);
|
return database.collectionExists(`_Join:${fieldName}:${className}`).then(exist => {
|
||||||
|
if (exist) {
|
||||||
|
return database.dropCollection(`_Join:${fieldName}:${className}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// for non-relations, remove all the data.
|
// for non-relations, remove all the data.
|
||||||
|
|||||||
Reference in New Issue
Block a user