makandra / makandra-rubocop

makandra's default Rubocop configuration
MIT License
6 stars 1 forks source link

Discussion: Rails/InverseOf #14

Closed FLeinzi closed 4 years ago

FLeinzi commented 4 years ago

https://www.rubydoc.info/gems/rubocop-rails/RuboCop/Cop/Rails/InverseOf

app/models/assignment_form.rb:9:3: C: Rails/InverseOf: Specify an :inverse_of option.
  belongs_to :assigned_user, class_name: 'User', foreign_key: :assigned_user_id
  ^^^^^^^^^^

Fix:

belongs_to :assigned_user, class_name: 'User', foreign_key: :assigned_user_id, inverse_of: false

There will be many situations especially in form models where we don't have an inverse relation for belongs_to. So we have to set them to inverse_of: false.

Is this what we really want? :+1: for keeping, :-1: for disabling the cop

foobear commented 4 years ago

Depending on the form model, you should maybe even have records behind a relation use a form model as well and need to use change_association in to express that properly.

Explicitly specifying inverse_of: false when you don't have an inverse is perfectly fine.

denzelem commented 4 years ago

Looks like we keep this cop, no change is needed.