Skip to content

Loading…

Support for Nested Data Structures #100

Closed
garth opened this Issue · 2 comments

3 participants

@garth

Problem

Our usecase is we are putting together data in our API from multiple sources and packaging to send to the UI.

We are using partly relational data from our DB (with id's) partly data from config documents and partly data gleaned from reflecting methods from plugins in our application (without id's).

This scenario could be considered to be very similar to data coming from a document store such as mongo or couch, and a solution would probably fix those cases also.

The following is a small example data structure extracted from a much larger structure. Hopefully it demonstrates most issues:

{
  "group": {
    "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30",
    "name": "Group 1",
    "rules": [
      {
        "target": "ObjectType",
        "name": "Rule Name",
        "appliesOn": ["Monday", "Tuesday",
                      "Wednesday", "Thursday",
                      "NotNationalHoliday"],
        "parameters": {
          "startTime": 570,
          "endTime": 960,
          "requireRemarks": false
        }
      }
    ]
  }
}

In order to handle this example we need attribute arrays (#96), dictionaries where value type is not pre-defined (#71 or similar), and nested models that only exist in the context of their parent (ie, they don't have their own id). Also when we commit changes to this structure we need to POST the whole structure, not just the sub-model-element that changed.

Of course we could break this structure down into a pseudo-relational representation, but things start getting large and ugly:

{
  "group": {
    "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30",
    "name": "Group 1",
    "rules": [
      {
        "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30_rule1",
        "target": "ObjectType",
        "name": "Rule Name",
        "appliesOn": [
          {
            "id": 1,
            "name": "Monday"
          },
          {
            "id": 2,
            "name": "Tuesday"
          },
          {
            "id": 3,
            "name": "Wednesday"
          },
          {
            "id": 4,
            "name": "Thursday"
          },
          {
            "id": 8,
            "name": "NotNationalHoliday"
          }
        ],
        "parameters": [
          {
            "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30_rule1_param1"
            "name": "startTime",
            "value": "570"
          },
          {
            "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30_rule1_param2"
            "name": "endTime",
            "value": "960"
          },
          {
            "id": "099bfb6c-71c0-4b6d-99bc-0d475df37e30_rule1_param3"
            "name": "strequireRemarksartTime",
            "value": "false"
          }
        ]
      }
    ]
  }
}

This structure would probably load, but changes could be difficult to manage, since some sub-elements do not have meaning outside of their context, so we really need to POST back the whole document.

Ideas for Discussion

  • Add a DS.SubModel that can only exist in the context of a DS.Model, changes to a DS.SubModel would cause the parent DS.Model to be commited (including all sub models).
  • Add support for primitive type arrays within a model attribute such as #96
  • Add support for dictionary sets within a model attribute
@wycats
Ember.js member

This is a dup of #53

@wycats wycats closed this
@ashugit

Hi Garth,
Facing the exact issue, what was the best way to apply EmberJS on data set like that ?
Your help would be a big saviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.