In postgres, they support unique indexes with conditions. For this example, you'd create the index with: CREATEUNIQUE INDEXphone_number_unique_primary_for_userON"PhoneNumber"(user_id, is_primary)WHERE(is_primary=true); This is possible within Rails' ActiveRecord validations, which I've used ...