@@ -54,6 +54,7 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
5454 return source ;
5555 }
5656
57+ console . log ( '==================' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
5758 const dbOptionsByFieldName : Map < string , IDbOptions >
5859 = Reflect . getMetadata ( dbSymbols . dbByFieldName , target ) || new Map < string , IDbOptions > ( ) ;
5960
@@ -63,6 +64,7 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
6364
6465 // convert the DB key name to the Model key name
6566 const mapper = map ( key , source [ key ] , dbOptionsByFieldName ) ;
67+ if ( key === 'tag' ) console . log ( '================== mapper' . cyan , JSON . stringify ( mapper , null , 2 ) . cyan ) ;
6668 const model = mapper . model ;
6769
6870 let nextTarget ;
@@ -73,7 +75,9 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
7375 } catch ( err ) {
7476 throw new Error ( `Model '${ modelName } ' has a property '${ key } ' that defines its model with a value that`
7577 + ` cannot be constructed` ) ;
76- }
78+ }
79+
80+ console . log ( '================== 111111' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
7781
7882 if ( model || shouldRecurse ( source [ key ] ) ) {
7983
@@ -87,12 +91,13 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
8791 const values = [ ] ;
8892
8993 for ( const src of source [ key ] ) {
94+ console . log ( '==================src' . cyan , src ) ;
95+ nextTarget = ( model ) ;
9096 values . push ( Object . assign ( new model ( ) , mapDbToModel ( src , nextTarget , map ) ) ) ;
9197 }
9298 value = values ;
9399
94100 } else {
95-
96101 value = mapDbToModel ( source [ key ] , nextTarget , map , ++ depth ) ;
97102
98103 if ( model ) {
@@ -103,20 +108,23 @@ export function fromDb(json: any, options?: IFromDbOptions): object {
103108 }
104109 }
105110 }
106-
111+ console . log ( '================== >>>>>>>' . cyan , mapper . newKey ) ;
107112 target [ mapper . newKey ] = value ;
108113 }
109114
110115 } else {
111116 // otherwise, map a property that has a primitive value or an ObjectID value
112117 if ( mapper . newKey !== undefined ) {
118+ console . log ( '================== %%%%%%' . cyan , `assigning ${ source [ key ] } to ${ mapper . newKey } ` ) ;
113119 target [ mapper . newKey ] = ( source [ key ] !== undefined && source [ key ] !== null )
114120 ? source [ key ]
115121 : nextTarget ; // resolves issue #94
116122 }
117123 }
124+ console . log ( '================== 222222' . zebra . green , JSON . stringify ( target , null , 2 ) . green ) ;
118125 }
119126
127+ if ( ! ! target . order ) console . log ( '==================' . zebra . red , JSON . stringify ( target , null , 2 ) . red ) ;
120128 return target ;
121129 }
122130
0 commit comments