Apply Rails/InverseOf rubocop rule

Not doing so has a few gotchas when working with relations, particularly
with records which are not stored in the database.

I'm excluding the related content file because it's got a very peculiar
relationship with itself: the `has_one :opposite_related_content` has no
inverse; the relation itself is its inverse. It's a false positive since
the inverse condition is true:

```
content.opposite_related_content.opposite_related_content.object_id ==
  content.object_id
```
This commit is contained in:
Javi Martín
2019-10-24 04:41:04 +02:00
parent 94d2496f8f
commit 42d2e5b3ad
37 changed files with 107 additions and 65 deletions

View File

@@ -11,12 +11,15 @@ class Poll::Question < ApplicationRecord
belongs_to :poll
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_questions
has_many :comments, as: :commentable
has_many :comments, as: :commentable, inverse_of: :commentable
has_many :answers, class_name: "Poll::Answer"
has_many :question_answers, -> { order "given_order asc" }, class_name: "Poll::Question::Answer", dependent: :destroy
has_many :question_answers, -> { order "given_order asc" },
class_name: "Poll::Question::Answer",
inverse_of: :question,
dependent: :destroy
has_many :partial_results
has_many :pair_answers
has_one :votation_type, as: :questionable
has_one :votation_type, as: :questionable, inverse_of: :questionable
belongs_to :proposal
attr_accessor :enum_type, :max_votes, :prioritization_type