Open aarona opened 10 months ago
Unfortunately, I'm unable to reproduce the error. Rails/UniqueValidationWithoutIndex
cop works model with db/schema.rb. Can you provide reproduction code for the error?
@koic Could you explain how rubocop
works withschema.rb
?
Error:
app/models/buyer_user_notifications_setting.rb:4:3: C: Rails/UniqueValidationWithoutIndex: Uniqueness validation should have a unique index on the database column.
validates :buyer_user_id, uniqueness: true
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Model:
validates :buyer_user_id, uniqueness: true
Schema:
create_table "buyer_user_notifications_settings", force: :cascade do |t|
...
t.index ["buyer_user_id"], name: "index_buyer_user_notifications_settings_on_buyer_user_id", unique: true
end
Migration:
add_index :buyer_user_notifications_settings, :buyer_user_id, unique: true, if_not_exists: true
pg_index:
Thank you!
Unfortunately, I'm unable to reproduce the error.
Rails/UniqueValidationWithoutIndex
cop works model with db/schema.rb. Can you provide reproduction code for the error?
I think that might be the issue here then. This is a simple website that actually has no ActiveRecord
models associated with it. Just my POROs that are grabbing ActiveRecord
functionality through some includes. Here's all of the code in my db/schema.rb
file:
ActiveRecord::Schema.define(version: 0) do
end
Regardless, it seems that @yashka713 still has this problem even with real ActiveRecord
models in their project.
Expected behavior
Expected rubocop to run without errors.
Actual behavior
Received the following errors:
Steps to reproduce the problem
Every single error was related to lines where I'm using
validates
. Here are some examples:It might be important to note this project doesn't have any
ActiveRecord
model classes and that these aren't actually* < ActiveRecord::Base
classes but are POROs that include some Rails functionality so they behave like ActiveRecord classes. Here's an example:Also note that I'm using
ruby 3.3.0p0
as well. I'm assuming because of the text in the errors though that this might be arubocop-rails
bug and not necessarily arubocop
bug.RuboCop version