@@ -54,7 +54,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
5454 return source ;
5555 }
5656
57- console . log ( '==================' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
5857 const dbOptionsByFieldName : Map < string , IDbOptions >
5958 = Reflect . getMetadata ( dbSymbols . dbByFieldName , target ) || new Map < string , IDbOptions > ( ) ;
6059
@@ -64,7 +63,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
6463
6564 // convert the DB key name to the Model key name
6665 const mapper = map ( key , source [ key ] , dbOptionsByFieldName ) ;
67- if ( key === 'tag' ) console . log ( '================== mapper' . cyan , JSON . stringify ( mapper , null , 2 ) . cyan ) ;
6866 const model = mapper . model ;
6967
7068 let nextTarget ;
@@ -77,8 +75,6 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
7775 + ` cannot be constructed` ) ;
7876 }
7977
80- console . log ( '================== 111111' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
81-
8278 if ( model || shouldRecurse ( source [ key ] ) ) {
8379
8480 // if the key should be included
@@ -91,9 +87,10 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
9187 const values = [ ] ;
9288
9389 for ( const src of source [ key ] ) {
94- console . log ( '==================src' . cyan , src ) ;
95- nextTarget = ( model ) ;
9690 values . push ( Object . assign ( new model ( ) , mapDbToModel ( src , nextTarget , map ) ) ) ;
91+ nextTarget = ( model )
92+ ? Object . assign ( new model ( ) , target [ mapper . newKey ] )
93+ : target [ mapper . newKey ] ;
9794 }
9895 value = values ;
9996
@@ -108,23 +105,19 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
108105 }
109106 }
110107 }
111- console . log ( '================== >>>>>>>' . cyan , mapper . newKey ) ;
112108 target [ mapper . newKey ] = value ;
113109 }
114110
115111 } else {
116112 // otherwise, map a property that has a primitive value or an ObjectID value
117- if ( mapper . newKey !== undefined ) {
118- console . log ( '================== %%%%%%' . cyan , `assigning ${ source [ key ] } to ${ mapper . newKey } ` ) ;
113+ if ( mapper . newKey !== undefined ) {
119114 target [ mapper . newKey ] = ( source [ key ] !== undefined && source [ key ] !== null )
120115 ? source [ key ]
121116 : nextTarget ; // resolves issue #94
122117 }
123118 }
124- console . log ( '================== 222222' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
125119 }
126120
127- if ( ! ! target . order ) console . log ( '==================' . zebra . red , JSON . stringify ( target , null , 2 ) . red ) ;
128121 return target ;
129122 }
130123
0 commit comments