diff --git a/app/models/activity.rb b/app/models/activity.rb index 52d720c83..a0c862c25 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -1,6 +1,6 @@ class Activity < ApplicationRecord belongs_to :actionable, -> { with_hidden }, polymorphic: true - belongs_to :user, -> { with_hidden } + belongs_to :user, -> { with_hidden }, inverse_of: :activities VALID_ACTIONS = %w[hide block restore valuate email] diff --git a/app/models/budget/investment/change_log.rb b/app/models/budget/investment/change_log.rb index 8ab4b0a75..fe5839b14 100644 --- a/app/models/budget/investment/change_log.rb +++ b/app/models/budget/investment/change_log.rb @@ -1,5 +1,9 @@ class Budget::Investment::ChangeLog < ApplicationRecord - belongs_to :author, -> { with_hidden }, class_name: "User", required: false + belongs_to :author, -> { with_hidden }, + class_name: "User", + foreign_key: "author_id", + inverse_of: :budget_investment_change_logs, + required: false validates :old_value, presence: true validates :new_value, presence: true diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 51d822c4c..3384f059e 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -6,7 +6,7 @@ class Legislation::Annotation < ApplicationRecord serialize :ranges, Array belongs_to :draft_version, foreign_key: "legislation_draft_version_id" - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :legislation_annotations has_many :comments, as: :commentable, dependent: :destroy validates :text, presence: true diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index ce5329709..133219591 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -20,7 +20,7 @@ class Legislation::Proposal < ApplicationRecord acts_as_paranoid column: :hidden_at belongs_to :process, foreign_key: "legislation_process_id" - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :legislation_proposals belongs_to :geozone has_many :comments, as: :commentable diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index c75d42165..17be22596 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -6,7 +6,7 @@ class Legislation::Question < ApplicationRecord translates :title, touch: true include Globalizable - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :legislation_questions belongs_to :process, foreign_key: "legislation_process_id" has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id", diff --git a/app/models/poll.rb b/app/models/poll.rb index 488cdcf28..46655d1b8 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -28,7 +28,7 @@ class Poll < ApplicationRecord has_many :ballot_sheets has_and_belongs_to_many :geozones - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :polls belongs_to :related, polymorphic: true belongs_to :budget diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 107cf03d9..7f4ce8a8f 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -1,6 +1,6 @@ class Poll::Answer < ApplicationRecord belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_answers delegate :poll, :poll_id, to: :question diff --git a/app/models/poll/pair_answer.rb b/app/models/poll/pair_answer.rb index 90bf5a374..18728388c 100644 --- a/app/models/poll/pair_answer.rb +++ b/app/models/poll/pair_answer.rb @@ -1,6 +1,6 @@ class Poll::PairAnswer < ApplicationRecord belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_pair_answers belongs_to :answer_right, class_name: "Poll::Question::Answer" belongs_to :answer_left, class_name: "Poll::Question::Answer" diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index 984704651..1ec31d9e0 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -2,7 +2,7 @@ class Poll::PartialResult < ApplicationRecord VALID_ORIGINS = %w[web booth] belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_partial_results belongs_to :booth_assignment belongs_to :officer_assignment diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index e3610a090..62f01d429 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -9,7 +9,7 @@ class Poll::Question < ApplicationRecord include Globalizable belongs_to :poll - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_questions has_many :comments, as: :commentable has_many :answers, class_name: "Poll::Answer" diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index 6c21f5daa..9895d99e8 100644 --- a/app/models/poll/recount.rb +++ b/app/models/poll/recount.rb @@ -1,7 +1,7 @@ class Poll::Recount < ApplicationRecord VALID_ORIGINS = %w[web booth letter].freeze - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_recounts belongs_to :booth_assignment belongs_to :officer_assignment diff --git a/app/models/topic.rb b/app/models/topic.rb index d90a521f1..1756969ef 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -4,7 +4,7 @@ class Topic < ApplicationRecord include Notifiable belongs_to :community - belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :topics has_many :comments, as: :commentable diff --git a/app/models/user.rb b/app/models/user.rb index 43990029f..e5b2847f4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,7 +24,12 @@ class User < ApplicationRecord has_many :debates, -> { with_hidden }, foreign_key: :author_id has_many :proposals, -> { with_hidden }, foreign_key: :author_id has_many :people_proposals, -> { with_hidden }, foreign_key: :author_id + has_many :activities has_many :budget_investments, -> { with_hidden }, foreign_key: :author_id, class_name: "Budget::Investment" + has_many :budget_investment_change_logs, + foreign_key: :author_id, + inverse_of: :author, + class_name: "Budget::Investment::ChangeLog" has_many :comments, -> { with_hidden } has_many :failed_census_calls has_many :notifications @@ -33,6 +38,40 @@ class User < ApplicationRecord has_many :legislation_answers, class_name: "Legislation::Answer", dependent: :destroy, inverse_of: :user has_many :follows has_many :budget_rol_assignments + has_many :legislation_annotations, + class_name: "Legislation::Annotation", + foreign_key: :author_id, + inverse_of: :author + has_many :legislation_proposals, + class_name: "Legislation::Proposal", + foreign_key: :author_id, + inverse_of: :author + has_many :legislation_questions, + class_name: "Legislation::Question", + foreign_key: :author_id, + inverse_of: :author + has_many :polls, foreign_key: :author_id, inverse_of: :author + has_many :poll_answers, + class_name: "Poll::Answer", + foreign_key: :author_id, + inverse_of: :author + has_many :poll_pair_answers, + class_name: "Poll::PairAnswer", + foreign_key: :author_id, + inverse_of: :author + has_many :poll_partial_results, + class_name: "Poll::PartialResult", + foreign_key: :author_id, + inverse_of: :author + has_many :poll_questions, + class_name: "Poll::Question", + foreign_key: :author_id, + inverse_of: :author + has_many :poll_recounts, + class_name: "Poll::Recount", + foreign_key: :author_id, + inverse_of: :author + has_many :topics, foreign_key: :author_id, inverse_of: :author has_many :budgets, through: :budget_rol_assignments has_many :votation_set_answers belongs_to :geozone