mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge pull request #1884 from bf4/simplify_relationship
* Simplify Relationship
This commit is contained in:
@@ -438,14 +438,7 @@ module ActiveModelSerializers
|
||||
allow_wildcard: true
|
||||
)
|
||||
serializer.associations(include_directive).each_with_object({}) do |association, hash|
|
||||
hash[association.key] = Relationship.new(
|
||||
serializer,
|
||||
association.serializer,
|
||||
instance_options,
|
||||
options: association.options,
|
||||
links: association.links,
|
||||
meta: association.meta
|
||||
).as_json
|
||||
hash[association.key] = Relationship.new(serializer, instance_options, association).as_json
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,18 +5,21 @@ module ActiveModelSerializers
|
||||
# {http://jsonapi.org/format/#document-resource-object-related-resource-links Document Resource Object Related Resource Links}
|
||||
# {http://jsonapi.org/format/#document-links Document Links}
|
||||
# {http://jsonapi.org/format/#document-resource-object-linkage Document Resource Relationship Linkage}
|
||||
# {http://jsonapi.org/format/#document-meta Docment Meta}
|
||||
def initialize(parent_serializer, serializer, serializable_resource_options, args = {})
|
||||
# {http://jsonapi.org/format/#document-meta Document Meta}
|
||||
def initialize(parent_serializer, serializable_resource_options, association)
|
||||
serializer = association.serializer
|
||||
options = association.options
|
||||
links = association.links
|
||||
meta = association.meta
|
||||
@object = parent_serializer.object
|
||||
@scope = parent_serializer.scope
|
||||
@association_options = args.fetch(:options, {})
|
||||
@association_options = options || {}
|
||||
@serializable_resource_options = serializable_resource_options
|
||||
@data = data_for(serializer)
|
||||
@links = args.fetch(:links, {}).each_with_object({}) do |(key, value), hash|
|
||||
@links = (links || {}).each_with_object({}) do |(key, value), hash|
|
||||
result = Link.new(parent_serializer, value).as_json
|
||||
hash[key] = result if result
|
||||
end
|
||||
meta = args.fetch(:meta, nil)
|
||||
@meta = meta.respond_to?(:call) ? parent_serializer.instance_eval(&meta) : meta
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user