-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
#as_json option :only Not working #1851
Comments
So, this isn't currently supported. Are there docs that suggest otherwise? I've been thinking about the differences between the AMS serializer api and the active model serialization api, but nothing's happened yet. Related #1845 |
@brosintoski Well, that's clearly a major fail on my part. Those comments weren't meant to stick around so long.
was meant for people reading the code to see that this should be implemented... I think if I just made it an issue it would get lost.. hmm |
@bf4 no problem. For now I just override With that said I'm open to any design that achieves filtering of base and associative attributes as a serialization option, so will just watch this project for updates. |
Good eyes on |
@brosintoski Mind include a snippet for anyone else whom it might help? (Or maybe it should even be a PR?) |
Happy to share the code but would consider it a stop gap solution for now due to how Here is the code:
|
@brosintoski yeah, method just part of an ongoing effort to improve the design, which is why I labeled it as api private :) |
Related #1643 |
Expected behavior vs actual behavior
Expected: Only fields passed to only option are returned from
as_json
.Actual: All fields/attributes of the serializer are returned.
Steps to reproduce
attributes :id, :name, :status
UserSerializer.new(User.new(name: 'foo bar', status: 'active')).as_json(only: [:id, :name]
)Environment
ActiveModelSerializers Version (commit ref if not on tag): aa4d89a
Output of
ruby -e "puts RUBY_DESCRIPTION"
: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]OS Type & Version: OS X v10.11.5
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)
The text was updated successfully, but these errors were encountered: