Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add Rails/UniqueValidationWithoutIndex cop #197
The target is the ActiveRecord's uniqueness validation.
When you define uniqueness validation in a model, you also should add a unique index.
First, duplicated records may occur even if ActiveRecord's validation is defined.
Second, it will cause slow queries.
And, I implemented a
This pull request adds
This cop ignores
But if someone sends a pull request to support the method, it will be acceptable. I just omitted it now to keep the first PR simple.
Before submitting the PR make sure the following are checked:
Oops, I found a false positive with validation for a relation.
# If the table has a unique index for `user_id` column, the following validation is not offensive. # But the cop registers an offense to the validation. belongs_to :user validates :user, uniqueness: true
I'll fix it soon.
Currently the cop does nothing if