Rubocop Rails/UniqueValidationWithoutIndex overfiring

321 Views Asked by At

I am getting the following lint error from Rubocopy:

app/models/slack_profile.rb:3 W: Rails/UniqueValidationWithoutIndex: Uniqueness validation should be with a unique index.

This corresponds to a uniqueness validation on the slack_user_id column of this model:

class SlackProfile < ApplicationRecord
  belongs_to :user
  validates :slack_user_id, presence: true, uniqueness: true
end

This is, this model does have a unique index, as evidenced here in schema.rb

  create_table "slack_profiles", force: :cascade do |t|
    t.integer "user_id",       limit: 4,   null: false
    t.string  "slack_user_id", limit: 255, null: false
  end

  add_index "slack_profiles", ["slack_user_id"], name: "index_slack_profiles_on_slack_user_id", unique: true, using: :btree
  add_index "slack_profiles", ["user_id"], name: "index_slack_profiles_on_user_id", unique: true, using: :btree

Am I missing something here? Is there something else I need to get a proper unique index?

0

There are 0 best solutions below