@@ -255,43 +255,53 @@ export function toJson(output: Relation[] | ArrowRelation[]): any {
255255 }
256256 }
257257
258- for ( let i = 0 ; i < relation . columns [ 0 ] . length ; i ++ ) {
259- let pathToSet = propPath . slice ( ) ;
260- let value : any ;
261-
262- for ( let j = 0 ; j < relation . columns . length ; j ++ ) {
263- const colValue = relation . columns [ j ] [ i ] ;
264- const pathIndex = columnLookup [ j ] ;
265-
266- if ( pathIndex !== undefined ) {
267- const isArray = pathToSet [ pathIndex ] === ARRAY_MARKER ;
268-
269- if ( isArray ) {
270- const arrayIndex =
271- typeof colValue === 'number'
272- ? colValue - 1 // rel indices start from 1, not 0
273- : i ; // wow, non-number array index?
274- pathToSet [ columnLookup [ j ] ] = arrayIndex ;
275- } else {
276- pathToSet [ columnLookup [ j ] ] = colValue as string | number ;
258+ // if the last key is a symbol, then we need to add it to the prop path
259+ // so we can set the value to an empty object
260+ if ( keys [ keys . length - 1 ] [ 0 ] === SYMBOL_PREFIX ) {
261+ propPath . push ( keys [ keys . length - 1 ] . slice ( 1 ) ) ;
262+ }
263+
264+ if ( relation . columns . length === 0 ) {
265+ set ( result , propPath , { } ) ;
266+ } else {
267+ for ( let i = 0 ; i < relation . columns [ 0 ] . length ; i ++ ) {
268+ let pathToSet = propPath . slice ( ) ;
269+ let value : any ;
270+
271+ for ( let j = 0 ; j < relation . columns . length ; j ++ ) {
272+ const colValue = relation . columns [ j ] [ i ] ;
273+ const pathIndex = columnLookup [ j ] ;
274+
275+ if ( pathIndex !== undefined ) {
276+ const isArray = pathToSet [ pathIndex ] === ARRAY_MARKER ;
277+
278+ if ( isArray ) {
279+ const arrayIndex =
280+ typeof colValue === 'number'
281+ ? colValue - 1 // rel indices start from 1, not 0
282+ : i ; // wow, non-number array index?
283+ pathToSet [ columnLookup [ j ] ] = arrayIndex ;
284+ } else {
285+ pathToSet [ columnLookup [ j ] ] = colValue as string | number ;
286+ }
287+ } else if ( j === relation . columns . length - 1 ) {
288+ value = colValue ;
277289 }
278- } else if ( j === relation . columns . length - 1 ) {
279- value = colValue ;
280290 }
281- }
282291
283- if (
284- pathToSet [ pathToSet . length - 1 ] === ARRAY_MARKER &&
285- keys [ keys . length - 1 ] === EMPTY_ARRAY_MARKER
286- ) {
287- pathToSet = pathToSet . slice ( 0 , - 1 ) ;
288- value = [ ] ;
289- } else if ( value === undefined ) {
290- // present value
291- value = { } ;
292- }
292+ if (
293+ pathToSet [ pathToSet . length - 1 ] === ARRAY_MARKER &&
294+ keys [ keys . length - 1 ] === EMPTY_ARRAY_MARKER
295+ ) {
296+ pathToSet = pathToSet . slice ( 0 , - 1 ) ;
297+ value = [ ] ;
298+ } else if ( value === undefined ) {
299+ // present value
300+ value = { } ;
301+ }
293302
294- set ( result , pathToSet , value ) ;
303+ set ( result , pathToSet , value ) ;
304+ }
295305 }
296306 } ) ;
297307
0 commit comments