Skip to content

Commit 2e791b6

Browse files
author
Colby Swandale
committed
circular bug fix, see: #211
1 parent 66d39b6 commit 2e791b6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/active_model/serializer/associations.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ def find_serializable(object)
9393
if target_serializer
9494
target_serializer.new(object, source_serializer.options)
9595
elsif object.respond_to?(:active_model_serializer) && (ams = object.active_model_serializer)
96-
ams.new(object, source_serializer.options)
96+
source_association = source_serializer.object.class.to_s.underscore.downcase
97+
plural_source_association = source_association+'s'
98+
except = ams._associations.keys.map(&:to_s).find do |association|
99+
association == source_association || association == plural_source_association
100+
end
101+
_options = source_serializer.options
102+
_options[:except] = Array(_options[:except])
103+
if not except.nil?
104+
if not _options[:except].include? except.to_sym
105+
_options[:except].push(except.to_sym)
106+
end
107+
end
108+
ams.new(object, _options)
97109
else
98110
object
99111
end

0 commit comments

Comments
 (0)