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

Nested associations for json adapter #1124

Conversation

NullVoxPopuli
Copy link
Contributor

Originally #1114 (I messed up the history because I merged instead of rebased)

This PR is based off of #1111, cause I needed the refactoring.

Discussion of idea here: #1113

Basically:

BlogSerializer < #...
  has_many :posts, include: { author: [:bio], comments: [:author]] }
end

resulting json may look like:

{
  blog: {
    posts: [
      {
        author: {
          bio: {...}
        },
        comments: [
          {  author: {...} }
        ]
      }
    ]
  }
}

See the included tests for more examples.

beauby and others added 2 commits September 7, 2015 12:11
initial refactor to make way for easy feature adding

refactored a bit more, and matched some method names to that of json_api

rename add_relationship methods to be less awkward

tests added

all tests tpass

remove binding.pry require

fixed app warnings

removed unused method

changed restrict_to to nested_associations and changed nested_relationships to nested_associations_to_include

removed unneeded parameter from add_resource_relationships

simplify key check

added another test, showing multiple relationship serializers

refactored include_array_to_hash to a utils module - this also simplified the test for it. yay
@joaomdmoura
Copy link
Member

related links:
#921
#1073

@NullVoxPopuli NullVoxPopuli deleted the nested-associations-for-json-adapter branch September 7, 2015 16:25
@NullVoxPopuli
Copy link
Contributor Author

cloned in favor of #1127 cause... I'm bad at squashing apparently

@joaomdmoura
Copy link
Member

😂

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

Successfully merging this pull request may close these issues.

4 participants