From 27ed26d6f26b45c7f17c69ea881bacb8662429cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 24 Oct 2019 03:42:51 +0200 Subject: [PATCH] Remove unnecessary class names in relations Just like we do in the Budget module, and in some places in the Poll and Legislation modules, we don't need to specify the class name when the name of the relation matches the name of a class in the same module. --- app/models/budget/investment.rb | 2 +- app/models/dashboard/executed_action.rb | 5 ++--- app/models/legislation/annotation.rb | 2 +- app/models/legislation/answer.rb | 5 ++--- app/models/legislation/draft_version.rb | 4 ++-- app/models/legislation/people_proposal.rb | 2 +- app/models/legislation/process.rb | 13 ++++--------- app/models/legislation/proposal.rb | 2 +- app/models/legislation/question.rb | 2 +- app/models/legislation/question_option.rb | 4 ++-- app/models/poll/ballot.rb | 2 +- app/models/poll/ballot_sheet.rb | 2 +- app/models/poll/booth.rb | 2 +- app/models/poll/booth_assignment.rb | 2 +- app/models/poll/officer.rb | 4 ++-- app/models/poll/question.rb | 2 +- 16 files changed, 24 insertions(+), 31 deletions(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 477447436..b17e5f937 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -44,7 +44,7 @@ class Budget has_many :valuator_group_assignments, dependent: :destroy has_many :valuator_groups, through: :valuator_group_assignments - has_many :comments, -> { where(valuation: false) }, as: :commentable, class_name: "Comment" + has_many :comments, -> { where(valuation: false) }, as: :commentable has_many :valuations, -> { where(valuation: true) }, as: :commentable, class_name: "Comment" has_many :tracker_assignments, dependent: :destroy diff --git a/app/models/dashboard/executed_action.rb b/app/models/dashboard/executed_action.rb index 1acf53cd9..9c020fc7d 100644 --- a/app/models/dashboard/executed_action.rb +++ b/app/models/dashboard/executed_action.rb @@ -1,9 +1,8 @@ class Dashboard::ExecutedAction < ApplicationRecord belongs_to :proposal - belongs_to :action, class_name: "Dashboard::Action" + belongs_to :action - has_many :administrator_tasks, as: :source, dependent: :destroy, - class_name: "Dashboard::AdministratorTask" + has_many :administrator_tasks, as: :source, dependent: :destroy validates :proposal, presence: true, uniqueness: { scope: :action } validates :action, presence: true diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 9133471ae..51d822c4c 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -5,7 +5,7 @@ class Legislation::Annotation < ApplicationRecord serialize :ranges, Array - belongs_to :draft_version, class_name: "Legislation::DraftVersion", foreign_key: "legislation_draft_version_id" + belongs_to :draft_version, foreign_key: "legislation_draft_version_id" belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable, dependent: :destroy diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb index 22b901991..12895e0ce 100644 --- a/app/models/legislation/answer.rb +++ b/app/models/legislation/answer.rb @@ -2,9 +2,8 @@ class Legislation::Answer < ApplicationRecord acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id", - inverse_of: :answers, counter_cache: true - belongs_to :question_option, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_option_id", + belongs_to :question, foreign_key: "legislation_question_id", inverse_of: :answers, counter_cache: true + belongs_to :question_option, foreign_key: "legislation_question_option_id", inverse_of: :answers, counter_cache: true belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index e9da06546..985b98b2c 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -9,8 +9,8 @@ class Legislation::DraftVersion < ApplicationRecord translates :body, touch: true include Globalizable - belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" - has_many :annotations, class_name: "Legislation::Annotation", foreign_key: "legislation_draft_version_id", dependent: :destroy + belongs_to :process, foreign_key: "legislation_process_id" + has_many :annotations, foreign_key: "legislation_draft_version_id", dependent: :destroy validates_translation :title, presence: true validates_translation :body, presence: true diff --git a/app/models/legislation/people_proposal.rb b/app/models/legislation/people_proposal.rb index 733cf825f..c9b79989f 100644 --- a/app/models/legislation/people_proposal.rb +++ b/app/models/legislation/people_proposal.rb @@ -19,7 +19,7 @@ class Legislation::PeopleProposal < ApplicationRecord acts_as_votable acts_as_paranoid column: :hidden_at - belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" + belongs_to :process, foreign_key: "legislation_process_id" belongs_to :author, -> { with_hidden }, class_name: "User" has_many :comments, as: :commentable diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 443994506..e7cdc7bbc 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -25,18 +25,13 @@ class Legislation::Process < ApplicationRecord CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i - has_many :draft_versions, -> { order(:id) }, class_name: "Legislation::DraftVersion", - foreign_key: "legislation_process_id", - dependent: :destroy + has_many :draft_versions, -> { order(:id) }, foreign_key: "legislation_process_id", dependent: :destroy has_one :final_draft_version, -> { where final_version: true, status: "published" }, class_name: "Legislation::DraftVersion", foreign_key: "legislation_process_id" - has_many :questions, -> { order(:id) }, class_name: "Legislation::Question", - foreign_key: "legislation_process_id", dependent: :destroy - has_many :proposals, -> { order(:id) }, class_name: "Legislation::Proposal", - foreign_key: "legislation_process_id", dependent: :destroy - has_many :people_proposals, -> { order(:id) }, class_name: "Legislation::PeopleProposal", - foreign_key: "legislation_process_id", dependent: :destroy + has_many :questions, -> { order(:id) }, foreign_key: "legislation_process_id", dependent: :destroy + has_many :proposals, -> { order(:id) }, foreign_key: "legislation_process_id", dependent: :destroy + has_many :people_proposals, -> { order(:id) }, foreign_key: "legislation_process_id", dependent: :destroy validates_translation :title, presence: true validates :start_date, presence: true diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 8b96e59e3..ce5329709 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -19,7 +19,7 @@ class Legislation::Proposal < ApplicationRecord acts_as_votable acts_as_paranoid column: :hidden_at - belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" + belongs_to :process, foreign_key: "legislation_process_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 51fade1b5..c75d42165 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -7,7 +7,7 @@ class Legislation::Question < ApplicationRecord include Globalizable belongs_to :author, -> { with_hidden }, class_name: "User" - belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" + belongs_to :process, foreign_key: "legislation_process_id" has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index c6f846120..91edc3944 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -5,8 +5,8 @@ class Legislation::QuestionOption < ApplicationRecord translates :value, touch: true include Globalizable - belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id", inverse_of: :question_options - has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question + belongs_to :question, foreign_key: "legislation_question_id", inverse_of: :question_options + has_many :answers, foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question validates :question, presence: true validates_translation :value, presence: true diff --git a/app/models/poll/ballot.rb b/app/models/poll/ballot.rb index fc1959ff0..b27f01e9d 100644 --- a/app/models/poll/ballot.rb +++ b/app/models/poll/ballot.rb @@ -1,5 +1,5 @@ class Poll::Ballot < ApplicationRecord - belongs_to :ballot_sheet, class_name: "Poll::BallotSheet" + belongs_to :ballot_sheet validates :ballot_sheet_id, presence: true diff --git a/app/models/poll/ballot_sheet.rb b/app/models/poll/ballot_sheet.rb index 34d735201..448a38955 100644 --- a/app/models/poll/ballot_sheet.rb +++ b/app/models/poll/ballot_sheet.rb @@ -1,7 +1,7 @@ class Poll::BallotSheet < ApplicationRecord belongs_to :poll belongs_to :officer_assignment - has_many :ballots, class_name: "Poll::Ballot" + has_many :ballots validates :data, presence: true validates :poll_id, presence: true diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index d253c5c09..e8229ef6c 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -1,6 +1,6 @@ class Poll class Booth < ApplicationRecord - has_many :booth_assignments, class_name: "Poll::BoothAssignment" + has_many :booth_assignments has_many :polls, through: :booth_assignments has_many :shifts diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb index fa037ed21..5af8e804c 100644 --- a/app/models/poll/booth_assignment.rb +++ b/app/models/poll/booth_assignment.rb @@ -5,7 +5,7 @@ class Poll before_destroy :destroy_poll_shifts, only: :destroy - has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy + has_many :officer_assignments, dependent: :destroy has_many :officers, through: :officer_assignments has_many :voters has_many :partial_results diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb index 5ecb7a139..1070e99af 100644 --- a/app/models/poll/officer.rb +++ b/app/models/poll/officer.rb @@ -1,8 +1,8 @@ class Poll class Officer < ApplicationRecord belongs_to :user - has_many :officer_assignments, class_name: "Poll::OfficerAssignment" - has_many :shifts, class_name: "Poll::Shift" + has_many :officer_assignments + has_many :shifts has_many :failed_census_calls, foreign_key: :poll_officer_id validates :user_id, presence: true, uniqueness: true diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index bc0d8d5db..e3610a090 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -15,7 +15,7 @@ class Poll::Question < ApplicationRecord has_many :answers, class_name: "Poll::Answer" has_many :question_answers, -> { order "given_order asc" }, class_name: "Poll::Question::Answer", dependent: :destroy has_many :partial_results - has_many :pair_answers, class_name: "Poll::PairAnswer" + has_many :pair_answers has_one :votation_type, as: :questionable belongs_to :proposal