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

has_many not respecting serializer option when using render include: [...] #2473

Open
giorgenes opened this issue Jun 21, 2024 · 0 comments
Open

Comments

@giorgenes
Copy link

Expected behavior vs actual behavior

I had a weird bug happen to me today. After I added a include: [...] clause to my render statement, I notice one of my objects became a dump of the raw object json instead of using the serializer I specified on has_many.

I have a has_many :stuff, serializer: StuffSerializer.

It turned out that my stuff field wasn't included in the include: [...], which caused the framework to do a raw dump of the data. Adding stuff to include: [...] fixed the issue, but I believe this to be a bug.

Steps to reproduce

(e.g., detailed walkthrough, runnable script, example application)

class MySerializer < ActiveModel::Serializer
  belongs_to :something, serializer: SomethingSerializer
  has_many :stuff, serializer: StuffSerializer

  def stuff
     Stuff.all
  end
end

# in the controller
render json: list, include: [:something], serializer: MySerializer

Environment

ActiveModelSerializers Version (commit ref if not on tag):
0.10.13

Output of ruby -e "puts RUBY_DESCRIPTION":
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin22]

OS Type & Version:
Macos Sonoma 14.3.1 (23D60)

Integrated application and version (e.g., Rails, Grape, etc):
gem "rails", "~> 7.0.6"

Backtrace

(e.g., provide any applicable backtraces from your application)

N/A

Additonal helpful information

(e.g., Gemfile.lock, configurations, PR containing a failing test, git bisect results)

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

1 participant