oj_serializers icon indicating copy to clipboard operation
oj_serializers copied to clipboard

Can't name has_one associated ':options'

Open hulloitskai opened this issue 1 year ago • 1 comments

has_one :options doesn't seem to work—however, as a workaround, the following does work:

class MyThingSerializer < Oj::Serializer
  has_one :_options, as: :options, serializer: MyFancyOptionsSerializer do
    my_thing.options
  end
end

Any ideas behind the source of this strange behaviour?

hulloitskai avatar Dec 25 '24 03:12 hulloitskai

it seems the serializer class have an instance method called options already which use to accept options for the seriazlier. need to use other name since options is already taken.

noxasch avatar May 12 '25 05:05 noxasch