attribute options #19
Replies: 4 comments
-
In that case, the shorthand syntax detects the In this case, you would want to explicitly redefine the method: attribute def options
# some code
end |
Beta Was this translation helpful? Give feedback.
-
I need any good solution because I like your project. class OptionsFieldSerializer < Oj::Serializer
attributes :id
attribute
def options
options_field.options
end
end
OptionsFieldSerializer.one(OpenStruct.new(id: 1, options: {test: "value"}))
# => {:id=>1, :options=>nil} How long will implementation take? |
Beta Was this translation helpful? Give feedback.
-
Sorry for pinging but your solution(to redefine method) does not work.
class OptionsFieldSerializer < Oj::Serializer
attributes :id
attribute def options
options_field.options
end
end returns options that I use as the second argument OptionsFieldSerializer.one(OpenStruct.new(id: 1, options: {real_option: "real_value"}), oj_serializer_option: "oj_serializer_value");
#=> {:id=>1, :options=>{:oj_serializer_option=>"oj_serializer_value"}} returns nil because the second argument is nil OptionsFieldSerializer.one(OpenStruct.new(id: 1, options: {real_option: "real_value"}))
#=> {:id=>1, :options=>nil} expected behavior {:id=>1, :options=>{:real_option => "real_value"}} |
Beta Was this translation helpful? Give feedback.
-
It works if I use attribute :any_name, root: :options do
...
end |
Beta Was this translation helpful? Give feedback.
-
Our project has records with options fields
when I try use it as
I get options that I used in one/many
Beta Was this translation helpful? Give feedback.
All reactions