CoursePark / KnexNest

A wrapper for Knex.js that can output list of objects hydrated from a select
76 stars 10 forks source link

Nested object returns as null if first property is null #7

Open hannupekka opened 5 years ago

hannupekka commented 5 years ago

Given the query const query = knex.select(['table.col_a AS _nested_colA','table.col_b AS _nested_colB']);

am I right to assume that with table.col_a as null and table.col_b as foo I should be getting back

{
  nested: {
    colA: null,
    colB: 'foo'
  }
}

However, I get

{
  nested: null
}

Is this how it should be working or might this be a bug?

hannupekka commented 5 years ago

I've forked this project and added test data to hilight the issue: https://github.com/hannupekka/KnexNest/tree/issue/7-nested-objects-return-as-null

The reason for this seems to be at https://github.com/CoursePark/NestHydrationJS/blob/master/NestHydrationJS.js#L98 - if I remove that else block, nested null values seem to get returned properly.