Suppose the following DB migration in Ruby:
create_table :question_votes do |t| t.integer :user_id t.integer :question_id t.integer :vote
From RailsGuides. validates works too:
validates
class QuestionVote < ActiveRecord::Base validates :user_id, :uniqueness => { :scope => :question_id } end