Skip to content

Commit e0b74d8

Browse files
committed
Merge pull request #1096 from beauby/fix-attribute
Fix definition of serializer attributes with multiple calls to `attri…
2 parents 8d3a89e + 995bbcc commit e0b74d8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.attribute(attr, options = {})
7070
ActiveModelSerializers.silence_warnings do
7171
define_method key do
7272
object.read_attribute_for_serialization(attr)
73-
end unless respond_to?(key, false) || _fragmented.respond_to?(attr)
73+
end unless (key != :id && method_defined?(key)) || _fragmented.respond_to?(attr)
7474
end
7575
end
7676

test/fixtures/poro.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def custom_options
134134

135135
AuthorSerializer = Class.new(ActiveModel::Serializer) do
136136
cache key:'writer', skip_digest: true
137-
attributes :id, :name
137+
attribute :id
138+
attribute :name
138139

139140
has_many :posts
140141
has_many :roles

0 commit comments

Comments
 (0)