-
-
Save vamdt/75aca125883a88a9f1fd to your computer and use it in GitHub Desktop.
rails4 sti, custom "type" column name and value
This file contains hidden or 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 City < GeoEntity | |
def self.sti_name | |
3 | |
end | |
end |
This file contains hidden or 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 Country < GeoEntity | |
def self.sti_name | |
2 | |
end | |
end |
This file contains hidden or 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 GeoEntity < ActiveRecord::Base | |
self.inheritance_column = 'etype' | |
def self.find_sti_class(type_name) | |
self | |
end | |
end | |
This file contains hidden or 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 State < GeoEntity | |
def self.sti_name | |
1 | |
end | |
end |
This file contains hidden or 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 Zip < GeoEntity | |
def self.sti_name | |
4 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@vizo yes it doesn't return subclass.
My code for a lowercase string in 'type' with expected behaviour :