Search code examples
normalizr

Issu normalizing data ( entity with children of same entity )


i'm very new to normalizr.

I'm trying to normalize a json api answer that looks like this: http://myjson.com/15st3f

There are some nested elements of same entity. For exemple:

{
  "id": 1,
  "name": "a",
  [...]
  "children": [
    "id": 2,
    "name": "b",
    [...]
    "children": [
      "id": 3,
      "name": "c"
    ]
  ]
}

How should I start this? I'm a bit confuse. Can it be normalized? Can you have array of same entity, or something like that ? Can I do something like this ? :

const uor = new schema.Entity('uors', {
    UorChildren: [ uor ]
})

Solution

  • Use the define instance method:

    const uor = new schema.Entity('uors');
    uor.define({ children: [ uor ] });