Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Security Level: Public
-
Labels: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
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
Activity
Sergey Avseyev
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
Sergey Avseyev
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |