diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 2e53e2e7f..477447436 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -32,7 +32,7 @@ class Budget translates :description, touch: true include Globalizable - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :heading belongs_to :group belongs_to :budget diff --git a/app/models/budget/investment/change_log.rb b/app/models/budget/investment/change_log.rb index fa57a00dc..8ab4b0a75 100644 --- a/app/models/budget/investment/change_log.rb +++ b/app/models/budget/investment/change_log.rb @@ -1,5 +1,5 @@ class Budget::Investment::ChangeLog < ApplicationRecord - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id", required: false + belongs_to :author, -> { with_hidden }, class_name: "User", required: false validates :old_value, presence: true validates :new_value, presence: true diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index c13a7825c..10b16a2d3 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -12,7 +12,7 @@ class Budget include Sanitizable belongs_to :budget - belongs_to :next_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id + belongs_to :next_phase, class_name: "Budget::Phase" has_one :prev_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH } diff --git a/app/models/debate.rb b/app/models/debate.rb index dc1936e21..eb0b20fbd 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -24,7 +24,7 @@ class Debate < ApplicationRecord translates :description, touch: true include Globalizable - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :geozone has_many :comments, as: :commentable diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index bbd172ce0..c5742fe9e 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -1,6 +1,6 @@ class DirectMessage < ApplicationRecord - belongs_to :sender, class_name: "User", foreign_key: "sender_id" - belongs_to :receiver, class_name: "User", foreign_key: "receiver_id" + belongs_to :sender, class_name: "User" + belongs_to :receiver, class_name: "User" validates :title, presence: true validates :body, presence: true diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index aa5b95006..9133471ae 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, class_name: "Legislation::DraftVersion", foreign_key: "legislation_draft_version_id" - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable, dependent: :destroy validates :text, presence: true diff --git a/app/models/legislation/people_proposal.rb b/app/models/legislation/people_proposal.rb index 5bca21d11..733cf825f 100644 --- a/app/models/legislation/people_proposal.rb +++ b/app/models/legislation/people_proposal.rb @@ -20,7 +20,7 @@ class Legislation::PeopleProposal < ApplicationRecord acts_as_paranoid column: :hidden_at belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable validates :title, presence: true diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 93be27d6a..8b96e59e3 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, class_name: "Legislation::Process", foreign_key: "legislation_process_id" - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :geozone has_many :comments, as: :commentable diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index d28029305..51fade1b5 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :process, class_name: "Legislation::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 2fb7ed115..488cdcf28 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :related, polymorphic: true belongs_to :budget diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index ed9de7489..107cf03d9 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" delegate :poll, :poll_id, to: :question diff --git a/app/models/poll/pair_answer.rb b/app/models/poll/pair_answer.rb index 73d2b2d78..90bf5a374 100644 --- a/app/models/poll/pair_answer.rb +++ b/app/models/poll/pair_answer.rb @@ -1,8 +1,8 @@ class Poll::PairAnswer < ApplicationRecord belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" - belongs_to :answer_right, class_name: "Poll::Question::Answer", foreign_key: "answer_rigth_id" - belongs_to :answer_left, class_name: "Poll::Question::Answer", foreign_key: "answer_left_id" + belongs_to :author, -> { with_hidden }, class_name: "User" + belongs_to :answer_right, class_name: "Poll::Question::Answer" + belongs_to :answer_left, class_name: "Poll::Question::Answer" delegate :poll, :poll_id, to: :question diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index bacd1dda1..984704651 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :booth_assignment belongs_to :officer_assignment diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index e4830a433..bc0d8d5db 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable has_many :answers, class_name: "Poll::Answer" diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index b24fddac1..cb431b9b2 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -9,7 +9,7 @@ class Poll::Question::Answer < ApplicationRecord accepts_nested_attributes_for :documents, allow_destroy: true - belongs_to :question, class_name: "Poll::Question", foreign_key: "question_id" + belongs_to :question, class_name: "Poll::Question" has_many :videos, class_name: "Poll::Question::Answer::Video" validates_translation :title, presence: true diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb index cc5d3c101..6cf9e7cc6 100644 --- a/app/models/poll/question/answer/video.rb +++ b/app/models/poll/question/answer/video.rb @@ -1,5 +1,5 @@ class Poll::Question::Answer::Video < ApplicationRecord - belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id" + belongs_to :answer, class_name: "Poll::Question::Answer" VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index a972bc726..6c21f5daa 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :booth_assignment belongs_to :officer_assignment diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 1d69690ae..90417d85c 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -35,7 +35,7 @@ class Proposal < ApplicationRecord include Globalizable translation_class_delegate :retired_at - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" belongs_to :geozone has_many :comments, as: :commentable, dependent: :destroy has_many :proposal_notifications, dependent: :destroy diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index a59e0145b..829c863f8 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -2,7 +2,7 @@ class ProposalNotification < ApplicationRecord include Graphqlable include Notifiable - belongs_to :author, class_name: "User", foreign_key: "author_id" + belongs_to :author, class_name: "User" belongs_to :proposal validates :title, presence: true diff --git a/app/models/related_content.rb b/app/models/related_content.rb index 25a46c6c4..0903e4433 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -5,7 +5,7 @@ class RelatedContent < ApplicationRecord acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :author, class_name: "User", foreign_key: "author_id" + belongs_to :author, class_name: "User" belongs_to :parent_relationable, polymorphic: true, touch: true belongs_to :child_relationable, polymorphic: true, touch: true has_one :opposite_related_content, class_name: "RelatedContent", foreign_key: :related_content_id diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index 3a38e1352..26d7ec072 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -1,6 +1,6 @@ class SignatureSheet < ApplicationRecord belongs_to :signable, polymorphic: true - belongs_to :author, class_name: "User", foreign_key: "author_id" + belongs_to :author, class_name: "User" VALID_SIGNABLES = %w[Proposal Budget::Investment] diff --git a/app/models/topic.rb b/app/models/topic.rb index fad39ee42..d90a521f1 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", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable diff --git a/app/models/votation_set_answer.rb b/app/models/votation_set_answer.rb index f115b82b7..fd4b07d09 100644 --- a/app/models/votation_set_answer.rb +++ b/app/models/votation_set_answer.rb @@ -1,6 +1,6 @@ class VotationSetAnswer < ApplicationRecord belongs_to :votation_type - belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :author, -> { with_hidden }, class_name: "User" scope :by_author, -> (author) { where(author: author) } end