def add_info
describables << PublicProductInfo.create(:stuff=>"blah")
end
end
I've noticed that this would insert two records into 'product_descriptions' table. Doing backtracing in debug mode it seems that the first insert is triggered by has_many_polymorphs during array append operation (as expected). However, the second one seems to be happening as if it was a regular has_many relationship. The latter one is undesirable. The fix for that was to change
I stumbled upon a situation where join model would get inserted two records whenever has_many_polymorphs was used.
Here is the scenario
class Item < ActiveRecord::Base
after_create :add_info
has_many_polymorphs :describables, :from => [:public_product_infos, :propriatary_product_infos], :through => :product_descriptions
def add_info describables << PublicProductInfo.create(:stuff=>"blah") end
end
I've noticed that this would insert two records into 'product_descriptions' table. Doing backtracing in debug mode it seems that the first insert is triggered by has_many_polymorphs during array append operation (as expected). However, the second one seems to be happening as if it was a regular has_many relationship. The latter one is undesirable. The fix for that was to change
after_create
to
after_save