-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False Rails/HasManyOrHasOneDependent
warning
#528
Comments
Rails/HasManyOrHasOneDependent
warning
There are no warnings when it's written as:
I don't think there's any reason to use the double splat ( |
…ndent` Fixes rubocop#528. This PR fixes a false positive for `Rails/HasManyOrHasOneDependent` when specifying `:dependent` strategy with double splat.
This is affected by changes in the keyword arguments in Ruby 3.0. One of the following changes is required: has_many(:items, dependent: :destroy) # I strongly recommend this.
has_many(:items, **{dependent: :destroy}) I've opened #530, the latter will be accepted, but I strongly recommend the former (It's simple and clear) . |
…many_or_has_one_dependent [Fix #528] Fix a false positive for `Rails/HasManyOrHasOneDependent`
Hi @koic, I have a situation that I believe it could fit on this issue, but I'm on ruby 2.7 yet. class MyClass < ApplicationRecord
DEFAULT_OPERATIONABLE_OPTIONS = { source: :operationable, dependent: :restrict_with_error }.freeze
has_many :items, DEFAULT_OPERATIONABLE_OPTIONS.merge(source_type: 'Item', through: :some_column)
has_many :things, DEFAULT_OPERATIONABLE_OPTIONS.merge(source_type: 'Thing', through: :some_column)
...
has_many :other_items, DEFAULT_OPERATIONABLE_OPTIONS.merge(source_type: 'OtherItem', through: :some_other_column)
has_many :other_things, DEFAULT_OPERATIONABLE_OPTIONS.merge(source_type: 'OtherThing', through: :some_other_column)
...
end I'm getting the same error when running rubocop, could this be a bug or this is not acceptable? I'm running on rubocop 1.25.1 (rubocop-rails 2.13.2), Rails 6.1.4.6 and ruby 2.7.2p137 [x86_64-linux], on the process of upgrading from rails 5.2. |
Hello,
Not sure if I'm doing this right or not, but I'm having some issues with
has_many
associations.Example
Here's an example:
Actual behaviour
Here's the warning message I get:
Specify a `:dependent` option. (convention:Rails/HasManyOrHasOneDependent)
But if I write this line like this, without keywords brackets, I get no warning:
Expected behaviour
No warning messages?
Specs
The text was updated successfully, but these errors were encountered: