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

expose collection cannot specify a :serializer #110

Closed
hlxwell opened this issue Sep 10, 2014 · 14 comments
Closed

expose collection cannot specify a :serializer #110

hlxwell opened this issue Sep 10, 2014 · 14 comments
Milestone

Comments

@hlxwell
Copy link

hlxwell commented Sep 10, 2014

If I wants to expose a array of objects, each one can use a serializer, but I didn't find any :each_serializer option there.

What I should do?

I made a pull request, it works for me, but I am not sure if it is the correct solution.

#106

@mattcl
Copy link

mattcl commented Oct 2, 2014

I would also like to see this addressed

@Sutto
Copy link
Owner

Sutto commented Oct 6, 2014

Having a look now, I'll tweak it slightly and see if this can fix it - It's also an issue (I believe) with paginated collections.

@Sutto
Copy link
Owner

Sutto commented Oct 6, 2014

Oh, and the short way - If you specify :each_serializer, also specify :serializer as the ArraySerializer in whatever AMS version you're using, if you're using AMS.

@hlxwell
Copy link
Author

hlxwell commented Oct 6, 2014

actually my requirement was very simple, so I didn't find the correct way to do it.

I just added below code to all model class then solved. doesn't need each_serializer

  def active_model_serializer
    "#{self.class.name}Serializer".constantize
  end

@Sutto
Copy link
Owner

Sutto commented Nov 16, 2014

I'm working on support for this at the moment - there are a few edge cases we need to keep in mind when doing so & hence I figured I'd update here:

  1. We have to use a check other than #to_a for 'collections' as hashes implement it, when we want to treat them as singular.
  2. We should respect if someone sets :serializer and :each_serializer, only using the first / not doing anything special.
  3. We need to support: Arrays, Sets and Scopes at a minimum.

This'll be pushed out in the newest release, apologies for the massive delays.

@hlxwell
Copy link
Author

hlxwell commented Nov 16, 2014

@Sutto Agree with your comments.

@DmitryKK
Copy link

DmitryKK commented May 6, 2015

@Sutto is there any progress?

@Sutto
Copy link
Owner

Sutto commented May 19, 2015

@DmitryKK there hadn't been, but going to do this for 1.12 in the next few days

@Sutto Sutto added this to the v1.12 milestone May 19, 2015
@Sutto
Copy link
Owner

Sutto commented May 19, 2015

Try the version in master - I just pushed rough support for this.

@DmitryKK
Copy link

Thanks, i tried. Serializer works only for the first record

@Sutto
Copy link
Owner

Sutto commented May 19, 2015

Have you got a specific example of what you're doing so I can try again?

On Tue, May 19, 2015 at 8:52 AM -0700, "Dmitry Krakosevich" [email protected] wrote:

Thanks, i tried. Serializer works only for the first record


Reply to this email directly or view it on GitHub.

@Sutto
Copy link
Owner

Sutto commented May 20, 2015

All good - Fixed and pushed

@Sutto Sutto closed this as completed May 20, 2015
@Sutto
Copy link
Owner

Sutto commented May 20, 2015

v1.12 is out now which fixes this. Thanks all!

@DmitryKK
Copy link

Perfect! Thank you very much

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

4 participants