Created
September 16, 2015 21:48
-
-
Save rafops/81ae3d1099547b5c85c5 to your computer and use it in GitHub Desktop.
Rails STI with type table
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 ItemType < ActiveRecord::Base | |
validates :title, presence: true, uniqueness: true | |
validates :class_name :presence: true, uniqueness: true | |
end | |
class Item < ActiveRecord::Base | |
belongs_to :item_type, foreign_key: :type, primary_key: :class_name | |
end | |
class SpecialItem < Item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment