Details
-
Improvement
-
Resolution: Fixed
-
Major
-
None
-
None
-
None
-
Security Level: Public
-
None
Description
(Pull request to fix this can be found here: https://github.com/couchbase/couchbase-ruby-model/pull/2 )
Currently, Couchbase::Model stores attributes (and views) in a class variable set to a mutable hash. This breaks the expected subclass attribute inheritance behavior that ActiveModel provides.
Example:
class A < Couchbase::Model
attribute :one
end
class B < A
attribute :two
end
B.attributes #=> {:one => nil, :two => nil}
A.attributes #=> {:one => nil, :two => nil}
B.attributes.object_id == A.attributes.object_id #=> true
This patch enables proper inheritance when ::Rails is present by using Class#class_attribute and detecting subclass additions to attribute:
class A < Couchbase::Model
attribute :one
end
class B < A
attribute :two
end
A.attributes #=> {:one => nil}
B.attributes #=> {:one => nil, :two => nil}
B.attributes.object_id != A.attributes.object_id #=> true