Skip to content

Documented alternative to 0.8 embed :ids, include: true in 0.10.x #2006

@goelinsights

Description

@goelinsights

Expected behavior vs actual behavior

I know this is a breaking change. However, I'm unable to replicate what I could do previously and despite a number of pull requests cited in previous issues, the fix appears to be to use the JSON-API adapter, e.g., @NullVoxPopuli #1111

(note: I have a number of duplicate objects nested and I want to sideload the data in a redux store that then filters the object by id in the front-end (angular 2). Since this is a front-end site, I'm trying to limit API calls as much as possible and cache as much as I can in each request on the front-end, especially for mobile offline use. I find the JSON API format counter-productive to this use case (included relative to original is irrelevant and the format is overly verbose for what is already a large data pull), so I'm trying to do in AMS 0.10.x what I could do easily in 0.8.x with the commands embed :ids, include: true). I've tried embed: :ids at the serializer level and it seems to nest the data in my serialized JSON rather than insert the id and sideload the associated data.

Is this still possible in AMS 0.10.x or should I stick to 0.8 or try the initializer in 0.9 that was deprecated?

Example desired output with objects referenced by id and then sideloaded into the root by object name:

{
  "authors": 
  [
    {"id": 1, "name": "Ghost Writer", "book_ids":[1,2,5, 7, 8, 9, 10, 15]}, 
    {"id":2, "name": "Celebrity Nonwriter", "book_ids":[1,5,15], "publisher_id": 3}
  ],
  "books": 
   [
     {"id": 1, "title": "Art of the Deal", "author_ids": [1,2], "publisher_id": 3}
    ],
   "publishers": [
     {"id": 3, "name": "Ghostwriter Press"}
    ]
}

Steps to reproduce

(e.g., detailed walkthrough, runnable script, example application)
tried to upgrade to 0.10.3 (via bundle update)

Environment

ActiveModelSerializers Version (commit ref if not on tag): 0.10.3

Output of ruby -e "puts RUBY_DESCRIPTION":

OS Type & Version:

Integrated application and version (e.g., Rails, Grape, etc): rails 4.2.6

Backtrace

(e.g., provide any applicable backtraces from your application)

Additonal helpful information

(e.g., Gemfile.lock, configurations, PR containing a failing test, git bisect results)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions