Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep nesting support #7

Closed
alexphys opened this issue Jun 22, 2017 · 1 comment
Closed

Deep nesting support #7

alexphys opened this issue Jun 22, 2017 · 1 comment

Comments

@alexphys
Copy link

alexphys commented Jun 22, 2017

Hi ,

Is there a way I can set this up to support deep nested objects?

Example;

{"data"=>
  {"id"=>"1",
   "attributes"=>
   {"attr1"=>true,
   "relationships"=>
    {"rel1"=>{"data"=>[{"attr1"=>"ok", "id"=>"1"}]},
     "rel2"=>
      {"data"=>
        [{"id"=>"1",
          "attributes"=>{"attr1"=>"true"},
          "relationships"=>
           {"rel2"=>{
            "rel3"=>
             {"data"=>
               [{"attributes"=>{"attr1"=>"10"},
                 "relationships"=>
                      ......

ActiveModelSerializers::Deserialization.jsonapi_parse(params, embedded: [:rel2])

The way this is now handled is deserializing only the top nested object

@spieker
Copy link
Owner

spieker commented Jun 26, 2017

You can not pass nested relationship names to the options at the moment but nested relationships are sent to the parse method of the deserializer along side with the options. So you can just add the nested relationships to the embedded once and they should serialize then.

{
  "data": {
    "id": "1",
    "type": "foo",
    "attributes": {
      "attr1": true
    },
    "relationships": {
      "bars": {
        "data": [{
          "type": "bar",
          "id": "1",
          "attributes": {
            "attr1": "ok"
          },
          "relationships": {
            "bazes": {
              "data": [{
                "type": "baz",
                "id": "x",
                "attributes": {
                  "attr1": "ok"
                }
              }]
            }
          }
        }]
      }
    }
  }
}

Then do

ActiveModelSerializers::Deserialization.jsonapi_parse(params, embedded: [:bars, :bazes])

@spieker spieker closed this as completed Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants