Support passing a custom ArraySerializer for has_many associations

Thanks @phoet

Closes #316
This commit is contained in:
Santiago Pastorino
2013-10-29 00:26:42 -02:00
parent ebe3afe716
commit 49ab359a34
3 changed files with 21 additions and 4 deletions

View File

@@ -158,10 +158,12 @@ end
def serialize(association)
associated_data = send(association.name)
if associated_data.respond_to?(:to_ary)
if associated_data.respond_to?(:to_ary) &&
!(association.serializer_class &&
association.serializer_class <= ArraySerializer)
associated_data.map { |elem| association.build_serializer(elem).serializable_hash }
else
association.build_serializer(associated_data).serializable_hash
association.build_serializer(associated_data).serializable_object
end
end
@@ -179,6 +181,6 @@ end
hash = attributes
hash.merge! associations
end
alias serializable_object serializable_hash
alias_method :serializable_object, :serializable_hash
end
end