Created
June 23, 2014 18:01
-
-
Save haileys/46a69db898943a659f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyBase < ActiveRecord::Base | |
def self.compute_type(type_name) | |
case type_name | |
when "MyBase"; MyBase | |
when "Foo"; Foo | |
when "Bar"; Bar | |
else super | |
end | |
end | |
end | |
class Foo < MyBase | |
end | |
class Bar < MyBase | |
end |
Ok, thank you, this works:
ActiveRecord::Base.store_full_sti_class = false # was true
User.last # will use the customized User.compute_type
Apparently, this might be what was preventing compute_type
from being called.
I can also confirm that find_sti_class
is being called. I just made a mistake and re-declared it as an instance method instead of class method. No wonder it wasn't being called.
Anyway, ActiveSupport::Dependencies.constantize(type_name)
isn't so bad.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to @pixeltrix, if
ActiveRecord::Base.store_full_sti_class
is true, then Rails will not callcompute_type
(but it will callfind_sti_class
, which you've said isn't being called... odd)