kwhitley / treeize

Converts row data (in JSON/associative array format) to tree structure based on column naming conventions.
MIT License
189 stars 24 forks source link

Regression in 2.1.0 for rows with nested objects #39

Closed rhinoceraptor closed 7 years ago

rhinoceraptor commented 7 years ago

Here is a minimal test case:

var treeize = require('treeize');
var tree = new treeize().setOptions({ output: { prune: false } });

var rows = [{
  primaryKey: 1,
  subObject: {
    key: 'field'
  },
  'subresources:id': 1,
  'subresources:field': 'Subresource 1',
}, {
  primaryKey: 1,
  subObject: {
    key: 'field'
  },
  'subresources:id': 2,
  'subresources:field': 'Subresource 2',
}];

console.log(JSON.stringify(tree.grow(rows).getData(), null, 2))

In 2.0.2, this will output:

[
  {
    "primaryKey": 1,
    "subObject": {
      "key": "field"
    },
    "subresources": [
      {
        "id": 1,
        "field": "Subresource 1"
      },
      {
        "id": 2,
        "field": "Subresource 2"
      }
    ]
  }
]

In 2.1.0, this will output:

[
  {
    "primaryKey": 1,
    "subObject": {
      "key": "field"
    },
    "subresources": [
      {
        "id": 1,
        "field": "Subresource 1"
      }
    ]
  },
  {
    "primaryKey": 1,
    "subObject": {
      "key": "field"
    },
    "subresources": [
      {
        "id": 2,
        "field": "Subresource 2"
      }
    ]
  }
]
kwhitley commented 7 years ago

Solved in 2.1.1, and added your test case specifically to future coverage. Certainly an edge case I never anticipated!

👍