diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 7addc6e6..f0fe62ae 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -103,5 +103,9 @@ module ActiveModel hash[name] = send(name) end end + + def associations + self.class._associations.dup + end end end diff --git a/test/serializers/associations_test.rb b/test/serializers/associations_test.rb index e019c073..46dcb63b 100644 --- a/test/serializers/associations_test.rb +++ b/test/serializers/associations_test.rb @@ -60,6 +60,25 @@ module ActiveModel assert_equal({post: {type: :belongs_to, options: {}}}, @comment_serializer.class._associations) end + + def test_associations + @comment_serializer_class.class_eval do + belongs_to :post + has_many :comments + end + + expected_associations = { + post: { + type: :belongs_to, + options: {} + }, + comments: { + type: :has_many, + options: {} + }, + } + assert_equal(expected_associations, @comment_serializer.associations) + end end end end