I am trying to make a has_many relation with the dynamic attribute class_name
class Category < ActiveRecord::Base has_many :ads, :class_name => ( lambda { return self.item_type } ) end
or
class Category < ActiveRecord::Base has_many :ads, :class_name => self.item_type end
But I got errors:
can't convert Proc into String
or
undefined method `item_type' for #<Class:0xb62c6c88>
EDIT I have two different types of ads
LeaseAd , RentAd they are implemented using unidirectional table inheritance
Then I have Category ads as a nested set. I would like to indicate dynamically which type of ads belongs to the Category object.
Thanks for the help!
ruby ruby-on-rails activerecord orm
vooD
source share