Sorry for my english if something goes wrong.
I have a model of Property
class Property <ActiveRecord:: Base
has_many: values,: class_name => “ProductProperty”
End
And correspondingly ProductProperty model in which values are stored.
class ProductProperty <ActiveRecord:: Base
belongs_to: product
belongs_to: property
end
Now the stored values are of type String. Do I have a need to store
different types of Integer, Boolean and String. I came up just one idea
how to implement it. Add to the model Property column type. And rewrite
the method values:
def values
case self.type
when ‘ProductPropertyString’
ProductPropertyString.where(:property_id => self.id)
when ‘ProductPropertyBoolean’
ProductPropertyBoolean.where(:property_id => self.id)
when ‘ProductPropertyInteger’
ProductPropertyInteger.where(:property_id => self.id)
end
Maybe somebody has already faced with this challenge and how to solve it
correctly?