File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -577,6 +577,38 @@ describe('Schema', () => {
577577 } ) ;
578578 } ) ;
579579
580+ it ( 'can delete relation field when related _Join collection not exist' , done => {
581+ config . database . loadSchema ( )
582+ . then ( schema => {
583+ schema . addClassIfNotExists ( 'NewClass' , {
584+ relationField : { type : 'Relation' , targetClass : '_User' }
585+ } )
586+ . then ( mongoObj => {
587+ expect ( mongoObj ) . toEqual ( {
588+ _id : 'NewClass' ,
589+ objectId : 'string' ,
590+ updatedAt : 'string' ,
591+ createdAt : 'string' ,
592+ relationField : 'relation<_User>' ,
593+ } ) ;
594+ } )
595+ . then ( ( ) => config . database . collectionExists ( '_Join:relationField:NewClass' ) )
596+ . then ( exist => {
597+ expect ( exist ) . toEqual ( false ) ;
598+ } )
599+ . then ( ( ) => schema . deleteField ( 'relationField' , 'NewClass' , config . database ) )
600+ . then ( ( ) => schema . reloadData ( ) )
601+ . then ( ( ) => {
602+ expect ( schema [ 'data' ] [ 'NewClass' ] ) . toEqual ( {
603+ objectId : 'string' ,
604+ updatedAt : 'string' ,
605+ createdAt : 'string'
606+ } ) ;
607+ done ( ) ;
608+ } ) ;
609+ } ) ;
610+ } ) ;
611+
580612 it ( 'can delete string fields and resave as number field' , done => {
581613 Parse . Object . disableSingleInstance ( ) ;
582614 var obj1 = hasAllPODobject ( ) ;
Original file line number Diff line number Diff line change @@ -409,7 +409,11 @@ class Schema {
409409
410410 if ( this . data [ className ] [ fieldName ] . startsWith ( 'relation<' ) ) {
411411 //For relations, drop the _Join table
412- return database . dropCollection ( `_Join:${ fieldName } :${ className } ` ) ;
412+ return database . collectionExists ( `_Join:${ fieldName } :${ className } ` ) . then ( exist => {
413+ if ( exist ) {
414+ return database . dropCollection ( `_Join:${ fieldName } :${ className } ` ) ;
415+ }
416+ } ) ;
413417 }
414418
415419 // for non-relations, remove all the data.
You can’t perform that action at this time.
0 commit comments