File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -655,4 +655,21 @@ describe('Schema', () => {
655
655
} ) ;
656
656
done ( ) ;
657
657
} ) ;
658
+
659
+ it ( 'ignore default field when merge with system class' , done => {
660
+ expect ( Schema . buildMergedSchemaObject ( {
661
+ _id : '_User' ,
662
+ username : 'string' ,
663
+ password : 'string' ,
664
+ authData : 'object' ,
665
+ email : 'string' ,
666
+ emailVerified : 'boolean'
667
+ } , {
668
+ authData : { type : 'string' } ,
669
+ customField : { type : 'string' } ,
670
+ } ) ) . toEqual ( {
671
+ customField : { type : 'string' }
672
+ } ) ;
673
+ done ( ) ;
674
+ } ) ;
658
675
} ) ;
Original file line number Diff line number Diff line change @@ -308,8 +308,12 @@ function mongoFieldTypeToSchemaAPIType(type) {
308
308
// is done in mongoSchemaFromFieldsAndClassName.
309
309
function buildMergedSchemaObject ( mongoObject , putRequest ) {
310
310
var newSchema = { } ;
311
+ let sysSchemaField = Object . keys ( defaultColumns ) . indexOf ( mongoObject . _id ) === - 1 ? [ ] : Object . keys ( defaultColumns [ mongoObject . _id ] ) ;
311
312
for ( var oldField in mongoObject ) {
312
313
if ( oldField !== '_id' && oldField !== 'ACL' && oldField !== 'updatedAt' && oldField !== 'createdAt' && oldField !== 'objectId' ) {
314
+ if ( sysSchemaField . length > 0 && sysSchemaField . indexOf ( oldField ) !== - 1 ) {
315
+ continue ;
316
+ }
313
317
var fieldIsDeleted = putRequest [ oldField ] && putRequest [ oldField ] . __op === 'Delete'
314
318
if ( ! fieldIsDeleted ) {
315
319
newSchema [ oldField ] = mongoFieldTypeToSchemaAPIType ( mongoObject [ oldField ] ) ;
@@ -318,6 +322,9 @@ function buildMergedSchemaObject(mongoObject, putRequest) {
318
322
}
319
323
for ( var newField in putRequest ) {
320
324
if ( newField !== 'objectId' && putRequest [ newField ] . __op !== 'Delete' ) {
325
+ if ( sysSchemaField . length > 0 && sysSchemaField . indexOf ( newField ) !== - 1 ) {
326
+ continue ;
327
+ }
321
328
newSchema [ newField ] = putRequest [ newField ] ;
322
329
}
323
330
}
You can’t perform that action at this time.
0 commit comments