use correct serializer for singular embeds in api (almost fixes #998)
This commit is contained in:
parent
536c458981
commit
a6fadc482f
1 changed files with 6 additions and 1 deletions
|
@ -41,7 +41,12 @@ module Api
|
|||
id_opts = opts.merge(key: "#{key}_id")
|
||||
attribute("#{attr}_id".to_sym,
|
||||
id_opts.merge(unless: -> { embeds.include?(key) }))
|
||||
attribute(key, opts.merge(if: -> { embeds.include?(key) }))
|
||||
attribute(key, opts.merge(if: -> { embeds.include?(key) })) do |serializer|
|
||||
child_object = serializer.object.send(key)
|
||||
child_serializer = "Api::V2::#{child_object.class.name}Serializer".constantize
|
||||
resource = child_serializer.new(child_object, scope: serializer.scope.merge(embeds: []))
|
||||
resource.as_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue