lib/jsonapi/resource_serializer.rb in jsonapi-resources-0.9.3 vs lib/jsonapi/resource_serializer.rb in jsonapi-resources-0.9.4
- old
+ new
@@ -285,10 +285,11 @@
relationships.each_with_object({}) do |(name, relationship), hash|
ia = include_directives[:include_related][name]
include_linkage = ia && ia[:include]
include_linked_children = ia && !ia[:include_related].empty?
+ options = { filters: ia && ia[:include_filters] || {} }
if field_set.include?(name)
hash[format_key(name)] = link_object(source, relationship, include_linkage)
end
# If the object has been serialized once it will be in the related objects list,
@@ -296,11 +297,11 @@
# through the relationships.
if include_linkage || include_linked_children
resources = if source.preloaded_fragments.has_key?(format_key(name))
source.preloaded_fragments[format_key(name)].values
else
- [source.public_send(name)].flatten(1).compact
+ [source.public_send(name, options)].flatten(1).compact
end
resources.each do |resource|
next if self_referential_and_already_in_source(resource)
id = resource.id
relationships_only = already_serialized?(relationship.type, id)
@@ -408,10 +409,13 @@
assoc.pluck(:type, :id).map do |type, id|
[type.underscore.pluralize, id]
end
end
else
- source.public_send(relationship.name).map do |value|
+ include_config = include_directives.include_config(relationship.name.to_sym) if include_directives
+ include_filters = include_config[:include_filters] if include_config
+ options = { filters: include_filters || {} }
+ source.public_send(relationship.name, options).map do |value|
[relationship.type, value.id]
end
end
linkage_types_and_values.each do |type, value|