multiple_table_inheritance
multiple_table_inheritance copied to clipboard
inherite and cast
Hi
first thanks for this gem, very usefull but im faced to a problem here my models
class ads < ActiveRecord::Base
attr_accessible : category_id, title, text, :ad_detail_attributes
has_one :ad_detail, :dependent => :destroy
accepts_nested_attributes_for :ad_detail, allow_destroy: true
...
end
class AdDetail < ActiveRecord::Base
attr_accessible :ad_id
acts_as_superclass
belongs_to :ad
end
class AdDetailsRealEstate < ActiveRecord::Base
attr_accessible :nb_rooms, :is_furnished, ...
inherits_from :AdDetail, :methods => true, :dependent => :destroy
end
AdDetailsCar < ActiveRecord::Base
attr_accessible :color, :brand, ...
inherits_from :AdDetail, :methods => true, :dependent => :destroy
end
when Im trying to do
a = Ad.first
a.ad_detail = AdDetailCar.new()
then I have this error
ActiveRecord::AssociationTypeMismatch: AdDetail(#33224200) expected, got AdDetailsCar(#30212560)
what is more strange is that it I do this,
xx = AdDetailCar.new(annonce_id => 1, :color => ...)
a = Ad.first
then I can access to ad.ad_detail without anyproblem.
Do I do anything bad ?
PS : another question, I install your gem with Gemfile, and the version I get is not the same than on github and have some small bugs for instance in inputs/base/collection.rb
def send_or_call_or_object(duck, object)
return object if object.is_a?(String) # TODO what about other classes etc?
send_or_call(duck, object)
end
whereas it should be according to github
def send_or_call_or_object(duck, object)
return object if object.is_a?(String) || object.is_a?(Integer) # TODO what about other classes etc?
send_or_call(duck, object)
end
this is oly bug I found, many there are other. Im quite new in RoR, it there a way to directly have the good version on Gemfile ?
thanks