Skip to content

Instantly share code, notes, and snippets.

@rafops
Created September 16, 2015 21:48
Show Gist options
  • Save rafops/81ae3d1099547b5c85c5 to your computer and use it in GitHub Desktop.
Save rafops/81ae3d1099547b5c85c5 to your computer and use it in GitHub Desktop.
Rails STI with type table
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