I have been reading a lot on the difference between STI and polymorphic associations and decided to use STI:
user.rb
Class User < ActiveRecord::Base
has_many :articles
end
article.rb
Class Article < ActiveRecord::Base
belongs_to :users
end
sport.rb
Class Sport < Article
end
politic.rb
Class Politic < Article
end
food.rb
Class Food < Article
end
create_table "articles", force: :cascade do |t|
t.string "title"
t.string "artwork"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "approved", default: false
t.string "type"
However, upon further reading, this becomes even more complicated. All I am really looking to do is to find some way to sort my articles by type. For example, is it possible that I simply have a string column tag
and specify that tag must be either politics, sports, or food
?