mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Allow serializers to receive instructions to
explicitly include or exclude specific lists of associations.
This commit is contained in:
@@ -372,7 +372,23 @@ module ActiveModel
|
||||
|
||||
def include_associations!(node)
|
||||
_associations.each do |attr, klass|
|
||||
include! attr, :node => node
|
||||
opts = { :node => node }
|
||||
|
||||
if options.include?(:include) || options.include?(:exclude)
|
||||
opts[:include] = included_association?(attr)
|
||||
end
|
||||
|
||||
include! attr, opts
|
||||
end
|
||||
end
|
||||
|
||||
def included_association?(name)
|
||||
if options.key?(:include)
|
||||
options[:include].include?(name)
|
||||
elsif options.key?(:exclude)
|
||||
!options[:exclude].include?(name)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user