jsonapi-serializer icon indicating copy to clipboard operation
jsonapi-serializer copied to clipboard

problem with nested serialization

Open zion03 opened this issue 9 years ago • 11 comments

I have nested object like user.UserBalances[0].Type for serialization

module.exports = {
  attributes: ['name', 'UserBalances'],
  UserBalances: {
    ref: 'id',
    included: true,
    attributes: ['user_id', 'Type'],
    Type: {
      ref: 'id',
      included: true,
      attributes: ['title']
    }
  }

All works fine except 3 level Type.

This is expected behavior, bug or I'm doing something wrong

zion03 avatar Apr 03 '17 08:04 zion03

@zion03 can you share me the "data input", the current "data output" and the expected result? Thanks!

SeyZ avatar Apr 06 '17 07:04 SeyZ

@SeyZ, @zion03 meant he wants to serialize nested relationships. The result of serialization should be like that:

{
  "data": {
    "type": "category",
    "id": "5715e6649a892006ae7224f7",
    "attributes": {
      "name": "Category name"
    },
    "relationships": {
      "article": {
        "data": {
          "type": "article",
          "id": "56fab7f59a8920070e34bec8"
        }
      }
    }
  },
  "included": [
    {
      "type": "article",
      "id": "56fab7f59a8920070e34bec8",
      "attributes": {
        "name": "Article name"
      },
      "relationships": {
        "author": {
          "data": {
            "type": "author",
            "id": "56f90cf59a8920070e34bec7"
          }
        },
        "editor": {
          "data": {
            "type": "editor",
            "id": "56f93a469a8920070d466517"
          }
        }
      }
    },
    {
      "type": "author",
      "id": "56f90cf59a8920070e34bec7",
      "attributes": {
        "name": "MyName"
      }
    },
    {
      "type": "editor",
      "id": "56f93a469a8920070d466517",
      "attributes": {
        "name": "MyName"
      }
    }
  ]
}

Could your library serialize nested relationships?

devdemi avatar May 16 '17 14:05 devdemi

@SeyZ, As I understood more then 2 level of nested relationships are not supported. Am I right?

devdemi avatar May 19 '17 12:05 devdemi

@devdemi According to the examples within the test examples here, the examples starting from line 984 show there is support for nested relationships. However I'm running into the same issues as @zion03 where the nested information is not being serialised into the top level included attribute.

charleytran avatar Jun 06 '17 05:06 charleytran

Any news on this? I just ran into the same problem...

patriq avatar Nov 24 '17 13:11 patriq

Yes, it seems more than two levels of relationships not working properly. Is there any solution?

ykh avatar Dec 01 '17 14:12 ykh

Any update on this?

pabloascarza avatar Dec 28 '17 13:12 pabloascarza

Also interested in a solution to this 👍

ynnoj avatar Jan 25 '18 17:01 ynnoj

I got this working with Mongoose 🎉

ynnoj avatar Jan 29 '18 20:01 ynnoj

@ynnoj could you enlighten us as to how you got it working?

reachtrevor avatar Jul 19 '18 17:07 reachtrevor

Probably this issue is related to #159 . I have the same issue when passing data from Objection because nested objects there are not "plain."

bvenchak avatar Oct 03 '19 15:10 bvenchak