You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected the execution context (self) to be the same when using something like has_one :something do as it is with attribute :something do. Maybe this is by design but it seems unusual.
This discovery came about as a result of trying to access instance_options which seems to not be possible (see Additional information)
Steps to reproduce
Given
class TestSerializer < ActiveModel::Serializer
attribute :attr do
self.class.name
end
has_one :child do
{ class: self.class.name }
end
end
well, attributes are on the object so don't need to be handled by a reflection like relations do.
I had thought you could yield the serializer instance to get access to that stuff. it's been a while since I've been in the code and I'm assuming you've read through the docs and code at this point, so I might be wrong.
Expected behavior vs actual behavior
Expected the execution context (
self
) to be the same when using something likehas_one :something do
as it is withattribute :something do
. Maybe this is by design but it seems unusual.This discovery came about as a result of trying to access
instance_options
which seems to not be possible (see Additional information)Steps to reproduce
Given
test output is
Environment
ActiveModelSerializers Version: v0.10.10
Output of
ruby -e "puts RUBY_DESCRIPTION"
: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]OS Type & Version: Linux Mint 20.1
Integrated application and version (e.g., Rails, Grape, etc): Rails 6.0
Additional helpful information
The following syntax doesn't work either as
instance_options
is protectedThe text was updated successfully, but these errors were encountered: