I\'m implementing functionality to track which articles a user has read.
create_table \"article\", :force => true do |t|
t.string \"title\"
t.
The order does matter in indexing.
[:user_id, :article_id], you can perform a fast query on user_id or user_id AND article_id, but NOT on article_id.Your migration add_index line should look something like this:
add_index :user_views, [:user_id, :article_id]
An easy way to do this in Rails is to use validates in your model with scoped uniqueness as follows (documentation):
validates :user, uniqueness: { scope: :article }