{"action":"created","issue":{"url":"https://api.github.com/repos/g-cassie/ember-drf/issues/14","labels_url":"https://api.github.com/repos/g-cassie/ember-drf/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/g-cassie/ember-drf/issues/14/comments","events_url":"https://api.github.com/repos/g-cassie/ember-drf/issues/14/events","html_url":"https://github.com/g-cassie/ember-drf/issues/14","id":96791459,"number":14,"title":"Multi-level relationships with sideloaded json","user":{"login":"nonovd","id":12936673,"avatar_url":"https://avatars.githubusercontent.com/u/12936673?v=3","gravatar_id":"","url":"https://api.github.com/users/nonovd","html_url":"https://github.com/nonovd","followers_url":"https://api.github.com/users/nonovd/followers","following_url":"https://api.github.com/users/nonovd/following{/other_user}","gists_url":"https://api.github.com/users/nonovd/gists{/gist_id}","starred_url":"https://api.github.com/users/nonovd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nonovd/subscriptions","organizations_url":"https://api.github.com/users/nonovd/orgs","repos_url":"https://api.github.com/users/nonovd/repos","events_url":"https://api.github.com/users/nonovd/events{/privacy}","received_events_url":"https://api.github.com/users/nonovd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-23T11:26:31Z","updated_at":"2015-08-06T14:32:15Z","closed_at":null,"body":"Hi,\r\nI'd like to sideload data with multi-level relationships such as :\r\n```json\r\n{\r\n    \"workoutPlan\": {\r\n        \"id\": 1999,\r\n        \"name\": \"Test Plan\",\r\n        \"workout_ids\": [ 12452, 12453 ],\r\n    },\r\n    \"workouts\": [\r\n        {\r\n            \"id\": 12452,\r\n            \"exercise_ids\": [ 114322 ]\r\n        },  {\r\n            \"id\": 12453,\r\n            \"exercise_ids\": [ 114323 ]\r\n        }\r\n    ],\r\n    \"exercises\": [\r\n        { \"id\": 114322 },\r\n        { \"id\": 114323 }\r\n    ]\r\n} \r\n```\r\nI tried to call the SideloadSerializer into sideloads:\r\n```python\r\nclass WorkoutPlanSideloadSerializer(SideloadSerializer):\r\n    class Meta:\r\n        base_serializer = WorkoutPlanSerializer\r\n        sideloads = [\r\n            (Workout,  WorkoutSideloadSerializer)\r\n        ]\r\n\r\nclass WorkoutSideloadSerializer(SideloadSerializer):\r\n    class Meta:\r\n        base_serializer = WorkoutSerializer\r\n        sideloads = [\r\n                (Exercise, ExerciseSerializer)\r\n        ]\r\n```\r\nBut I get something like:\r\n```json\r\n{\r\n    \"workoutPlan\": {\r\n        \"id\": 1999,\r\n        \"name\": \"Test Plan\",\r\n        \"workout_ids\": [ 12452, 12453 ],\r\n    },\r\n    \"workouts\": {\r\n        \"workouts\": [\r\n            {\r\n                \"id\": 12452,\r\n                \"exercise_ids\": [ 114322 ]\r\n            },  {\r\n                \"id\": 12453,\r\n                \"exercise_ids\": [ 114323 ]\r\n            }\r\n        ],\r\n        \"exercises\": [\r\n            { \"id\": 114322 },\r\n            { \"id\": 114323 }\r\n        ]\r\n    },\r\n} \r\n```\r\nIs there a way to get the correct json output ?\r\nThank you !\r\n"},"comment":{"url":"https://api.github.com/repos/g-cassie/ember-drf/issues/comments/128392916","html_url":"https://github.com/g-cassie/ember-drf/issues/14#issuecomment-128392916","issue_url":"https://api.github.com/repos/g-cassie/ember-drf/issues/14","id":128392916,"user":{"login":"g-cassie","id":4053345,"avatar_url":"https://avatars.githubusercontent.com/u/4053345?v=3","gravatar_id":"","url":"https://api.github.com/users/g-cassie","html_url":"https://github.com/g-cassie","followers_url":"https://api.github.com/users/g-cassie/followers","following_url":"https://api.github.com/users/g-cassie/following{/other_user}","gists_url":"https://api.github.com/users/g-cassie/gists{/gist_id}","starred_url":"https://api.github.com/users/g-cassie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/g-cassie/subscriptions","organizations_url":"https://api.github.com/users/g-cassie/orgs","repos_url":"https://api.github.com/users/g-cassie/repos","events_url":"https://api.github.com/users/g-cassie/events{/privacy}","received_events_url":"https://api.github.com/users/g-cassie/received_events","type":"User","site_admin":false},"created_at":"2015-08-06T14:32:15Z","updated_at":"2015-08-06T14:32:15Z","body":"I haven't tried this myself.  You could maybe get this result by making a fake field on `workoutPlan` called `exercise_ids`.  Then you could try something like this\r\n\r\n```python\r\nclass WorkoutPlanSideloadSerializer(SideloadSerializer):\r\n    class Meta:\r\n        base_serializer = WorkoutPlanSerializer\r\n        sideloads = [\r\n            (Workout,  WorkoutSerializer),  # These would be standard DRF serializers\r\n            (Exercise,  ExcerciseSerializer)\r\n        ]\r\n```\r\n\r\nThen you would hopefully get this output:\r\n\r\n```json\r\n{\r\n\"workoutPlans\": [\r\n  {\r\n    \"id\": 1,\r\n    \"name\": \"testPlan\",\r\n    \"exercise_ids\": [1, 2],\r\n    \"workout_ids\": [1, 2],\r\n }   \r\n],\r\n\"excercises\": [...],\r\n\"workouts\": [...]\r\n}"}}