rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Rails/HasManyOrHasOneDependent should check if the rule already matches for a relation without limiting scope

Open justin808 opened this issue 4 years ago • 3 comments

Rails/HasManyOrHasOneDependent should check if the rule already matches for a relation without limiting scope

  has_many :children, -> { dependent: :destroy, inverse_of: :parent, class_name: 'Parent'
  has_many :boy_children, -> { where(sex: 'boy') }, inverse_of: :parent, class_name: 'parent' # Needs rubocop:disable Rails/HasManyOrHasOneDependent

The second, scope-limited, relation should not need the dependent: destroy.


Expected behavior

The second, scope-limited, relation should not give a rule violation

Actual behavior

Rubocop shows rule violations

Steps to reproduce the problem

See above code example.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example: You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V, include them as well. Here's an example:

1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 2.7.3 x86_64-darwin20)
  - rubocop-performance 1.11.5
  - rubocop-rails 2.12.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.4.0

justin808 avatar Sep 16 '21 00:09 justin808

dup of https://github.com/rubocop/rubocop-rails/issues/541?

wilg avatar Oct 07 '21 21:10 wilg

oh i guess not nvm

wilg avatar Oct 07 '21 21:10 wilg

@koic This one is preventing me from upgrading, unless there is a workaround I am not thinking of? I think you've been working on this cop recently. Thoughts?

wilg avatar Oct 07 '21 21:10 wilg