mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Fix relationship behavior when using block
When using the relationships DSL with a block e.g. has_one :bio do link :self, "some_link" end the "data" field would be rendered with a nil value even though the bio is not nil. This happened because the block return value was set to nil but used as a value for the "data" field.
This commit is contained in:
@@ -42,17 +42,17 @@ module ActiveModel
|
||||
|
||||
def link(name, value = nil, &block)
|
||||
@_links[name] = block || value
|
||||
nil
|
||||
:nil
|
||||
end
|
||||
|
||||
def meta(value = nil, &block)
|
||||
@_meta = block || value
|
||||
nil
|
||||
:nil
|
||||
end
|
||||
|
||||
def include_data(value = true)
|
||||
@_include_data = value
|
||||
nil
|
||||
:nil
|
||||
end
|
||||
|
||||
def value(serializer)
|
||||
@@ -60,7 +60,12 @@ module ActiveModel
|
||||
@scope = serializer.scope
|
||||
|
||||
if block
|
||||
instance_eval(&block)
|
||||
block_value = instance_eval(&block)
|
||||
if block_value == :nil
|
||||
serializer.read_attribute_for_serialization(name)
|
||||
else
|
||||
block_value
|
||||
end
|
||||
else
|
||||
serializer.read_attribute_for_serialization(name)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user