Closed spoptchev closed 10 years ago
require 'virtus'
module BaseAddress
include Virtus.module
attribute :address1, String
end
module ExtendedAddress
include BaseAddress
end
module SomethingElse
include Virtus.module
end
class Entity
include Virtus.model
end
class ExtendedEntity < Entity
include ExtendedAddress, SomethingElse
end
extended_entity = ExtendedEntity.new(address1: '666 Pleasant Lane')
puts extended_entity.attributes # => {:address1=>"666 Pleasant Lane"}
Is it because you did not initialize ExtendedEntity
with a hash as above?
No, try this:
# just copy paste it into a file
require 'virtus'
module BaseAddress
include Virtus.module
attribute :address1, String
attribute :address2, String
end
module ExtendedAddress
include BaseAddress
attribute :base_address1, String
attribute :base_address2, String
end
module SomethingElse
include Virtus.module
attribute :something_else1, String
attribute :something_else2, String
end
class Entity
include Virtus.model
attribute :entity1, String
attribute :entity2, String
end
class ExtendedEntity < Entity
include ExtendedAddress, SomethingElse
end
extended_entity = ExtendedEntity.new(entity1: 1, something_else1: 'test', something_else2: 'testme')
puts extended_entity.attributes
In this case something_else1
and something_else2
are not in the attributes
hash.
It's the same issue (probably) as described in #274 so I'll fix it there and it should fix this one too
I have the following structure:
The last call to
extended_entity.attributes
does not return all declared attributes. The attributes fromBaseAddress
are missing. But I can still access theaddress1
attribute.You always get the attributes of the last included module and those that are declared on the class.