Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Default Serialization options for Collection #36

Open
standardtoaster opened this issue May 9, 2013 · 1 comment
Open

Default Serialization options for Collection #36

standardtoaster opened this issue May 9, 2013 · 1 comment

Comments

@standardtoaster
Copy link

It's possible to override the default serialization for a single record by overriding the to_json method, however, it would be nice to be able to apply the same global overrides to a collection of said resource

@aj0strow
Copy link

+1 it would be cool to have default associations option which would specify the association query options.

Usage could be something like:

class Article
  belongs_to :user
  has n, :comments

  serialization_scope :default, { 
      comments: { limit: 5, :created_at.gt => self.updated_at }, 
      user: { fields: [ :name ] } 
    }
end

@article.to_json(scope: :default)
# => { comments: [ {}, {}, {}, {}, {} ], user: {}, other fields... }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants