Polymorphic associations

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?

type attribute is of which model ?? I guess it is of property model
and
values method wrote inside property model, right ?

ProductPropertyString, ProductPropertyBoolean, ProductPropertyInteger
are
these models ??
if yes, why do you need association ?
“has_many: values,: class_name => ‘ProductProperty’”

On Tue, Apr 12, 2011 at 12:20 PM, Vasin Alexander
[email protected]wrote:

belongs_to: product
when ‘ProductPropertyString’


sαη∂ιρ Rαηѕιηg


twitter, github @sandipransing
skype sandip.ransing

class Property <ActiveRecord:: Base
has_many: values,: class_name => “ProductProperty”
End
It was in the original model.

In the amended accordingly will:
class Property <ActiveRecord:: Base
has_many :string_values,: class_name => “ProductPropertyString”
has_many :integer_values,: class_name => “ProductPropertyInteger”
has_many :boolean_values,: class_name => “ProductPropertyBoolean”
End

But I think this solution is clumsy.