-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Virtus with Modules (multiple layer include) - calling attributes does not return all declared attributes #260
Labels
Comments
spoptchev
changed the title
Using Virtus with Modules (multipy layer include) - calling attributes does not return all declared attributes
Using Virtus with Modules (multiple layer include) - calling attributes does not return all declared attributes
Apr 13, 2014
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 |
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 |
It's the same issue (probably) as described in #274 so I'll fix it there and it should fix this one too |
trptcolin
added a commit
to trptcolin/virtus
that referenced
this issue
Jul 11, 2014
Known caveat: if one module wants constructors/coercions/mass-assignment but the other one doesn't, the one that *does* want those features will win since it mixes in the module. fixes solnic#260 fixes solnic#274
trptcolin
added a commit
to trptcolin/virtus
that referenced
this issue
Jul 14, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: