Skip to content
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

Rails/HasManyOrHasOneDependent should not be an offence when the model is readonly #137

Closed
nunosilva800 opened this issue Oct 9, 2019 · 0 comments · Fixed by #473
Closed
Labels
enhancement New feature or request

Comments

@nunosilva800
Copy link

When you a have a readonly model (for example a model backed by a database view):

class NiceThing < ActiveRecord::Base 
  def readonly?
     true
  end
end

and you define an has_many relation such as: has_many :foos, foreign_key: :bar_id, then it does not make sense to enforce a dependent option.

Maybe this cop should be ignored when the class is readonly?, or at least be configurable to ignore those.

Do you think this is worthwhile?
I can try to implement this, but I actually don't really now if there are good determinist ways to detect if the class is readonly?, maybe just checking that the method is defined and that it evals to true? Sounds complicated, and dangerous...

@koic koic added the enhancement New feature or request label Apr 27, 2021
koic added a commit to koic/rubocop-rails that referenced this issue May 1, 2021
…donly?` is `true`

Fixes rubocop#137.

This PR makes `Rails/HasManyOrHasOneDependent` aware of `readonly?` is `true`.

There may be false positives or false negatives with just `def readonly? = true`,
but it makes it possible to detect perhaps general definition of `readonly?` method.
koic added a commit to koic/rubocop-rails that referenced this issue May 2, 2021
…donly?` is `true`

Fixes rubocop#137.

This PR makes `Rails/HasManyOrHasOneDependent` aware of `readonly?` is `true`.

There may be false positives or false negatives with just `def readonly? = true`,
but it makes it possible to detect perhaps general definition of `readonly?` method.
@koic koic closed this as completed in #473 May 2, 2021
koic added a commit that referenced this issue May 2, 2021
…ndent_aware_of_readonly_true

[Fix #137] Make `Rails/HasManyOrHasOneDependent` aware of `readonly` is `true`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants