1 | ActiveRecord::Base.set_inheritance_column :sti_type |
Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts
Wednesday, November 25, 2009
Customizing ur STI column name
To me, at least, :type is a very generic & commonly in use attribute name when doing modelling, and i don't see a good reason for activerecord to use it for STI (single table inheritance) support. To use my preferred naming strategy, i did the following inside RAILS_ROOT/config/initializers/active_record.rb
ActiveRecord: Bitten by :something & :something_id
I must have came across this previously, but i've forgotten all abt it, and today, i got bitten hard as a punishment for being forgetful. Let's same i have the following models:
During creating of sons, both the following strategies work:
But during update, only strategy 1 works:
DON'T FORGET !!!
1 | class Father < ActiveRecord::Base ; end |
During creating of sons, both the following strategies work:
1 | father1 = Father.create(:name => 'Papa Jones') |
But during update, only strategy 1 works:
1 | father2 = Father.create(:name => 'Papa Tommy') |
DON'T FORGET !!!
Subscribe to:
Posts (Atom)