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

The second level of serializers should still put their associations on the root #21

Closed
wycats opened this issue Dec 18, 2011 · 3 comments

Comments

@wycats
Copy link

wycats commented Dec 18, 2011

class PostSerializer < ApplicationSerializer
  embed :ids, :include => true
  has_many :comments
end

class CommentSerializer < ApplicationSerializer
  embed :ids, :include => true
  has_many :tags
end

The tags should be at the top root, not alongside comments.

@wycats
Copy link
Author

wycats commented Dec 18, 2011

One implementation would be to pass { root: root } as options into the serializer, and serializable_hash would insert the associations at the root, instead of making as_json responsible for inserting the associations alongside.

@ahawkins
Copy link
Contributor

{
  :post = {
    :title => 'Title 1',
    :content => 'Blah'
    comments: [1,3,4]
  },
  :comments => [
    { :title => 'Progamming', :tags => [1,2]},
    { :title => 'Programming Ruby', :tags => [1]}
  ],
  :tags => ['programming', 'ruby']
}

Is that what you're talking about?

@wycats
Copy link
Author

wycats commented Dec 20, 2011

Done and done.

@Adman65 no... the :tags would be an Array of Hashes containing IDs.

@wycats wycats closed this as completed Dec 20, 2011
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