Skip to content

Commit 02ad8c2

Browse files
committed
Fix CachingPostSerializer defining associations twice
1 parent 7485c84 commit 02ad8c2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/benchmark/fixtures.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,28 @@ class CachingCommentSerializer < CommentSerializer
5252
end
5353
Rails.configuration.serializers << CachingCommentSerializer
5454

55-
class CachingPostSerializer < PostSerializer
55+
# see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532
56+
class CachingPostSerializer < ActiveModel::Serializer
5657
cache key: 'post', expires_in: 0.1, skip_digest: true
58+
59+
attributes :id, :title, :body
60+
61+
has_many :comments, serializer: CommentSerializer
5762
belongs_to :blog, serializer: BlogSerializer
58-
belongs_to :author, serializer: CachingAuthorSerializer
59-
has_many :comments, serializer: CachingCommentSerializer
63+
belongs_to :author, serializer: AuthorSerializer
64+
65+
link(:post_authors) { 'https://example.com/post_authors' }
66+
67+
meta do
68+
{
69+
rating: 5,
70+
favorite_count: 10
71+
}
72+
end
73+
74+
def blog
75+
Blog.new(id: 999, name: 'Custom blog')
76+
end
6077
end
6178
Rails.configuration.serializers << CachingPostSerializer
6279

0 commit comments

Comments
 (0)