-
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
Execution context when using a block for has_one
vs attribute
#2415
Comments
Thanks for your report. What are you trying to do? |
In this case I was trying to access the |
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. |
The serializer is yielded but you can't access instance_options since its protected. Some options I can think of are:
fwiw, the work-around is just to use a method instead of a block |
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: