Is it possible to have one class containing tw

Hello fellow Rail-builders,

Is it possible to declare one class that includes two polymorphic
fields as such:

class Mark < ActiveRecord::Base

attribute: value, :string

belongs_to :markable, polymorphic => true

class Property < ActiveRecord::Base
has_one :name, :as => :markable
has_one :value, :as => :markable


Based on what I know of the underlying implementation, this looks
impossible. One alternative is to declare artificial classes
PropertyName and PropertyValue, each of which has_one :value, :as =>
markable and then change Property to has_one :property_name and has_one

class PropertyName < ActiveRecord::Base
has_one :value, :as => :markable

class PropertyValue < ActiveRecord::Base
has_one :value, :as => :markable

class Property < ActiveRecord::Base
has_one :property_name
has_one :property_value

, which isn’t that unnatural – however, just having additional classes
holding, only id references, seems like not as great as if the
polymorphic implementation in Mark class can actually allow Class#Field
as the value for markable_type.

What do you think? Any other suggestion? (BTW, yes, I suppose
Property can add :through assocation to directly access :markable for


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs