我試圖更改默認inheritance_column我所有的車型:默認inheritance_column名的ActiveRecord
# lib/change_sti_column.rb
module ChangeSTIColumn
def self.included(base)
base.class_eval do
self.inheritance_column = 'runtime_class'
end
end
end
ActiveRecord::Base.send(:include, ChangeSTIColumn)
看來的ActiveRecord :: Base的沒有得到它,但子類呢!
1.9.3-p484 :005 > ActiveRecord::Base.inheritance_column
=> "type"
1.9.3-p484 :005 > SubclassOfAR.inheritance_column
=> "type"
1.9.3-p484 :009 > SubclassOfAR.send(:include, ChangeSTIColumn).inheritance_column
=> "runtime_class"
那麼我該如何糾正這個問題才能使它適用於基類呢?
的ActiveRecord :: Base.inheritance_column =「RUNTIME_CLASS」不起作用。當然,我可以很容易地將其設置在我需要的每個課程中,但我只是想知道是否可以在全球範圍內進行更改。 –