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.
This commit is contained in:
Javi Martín
2019-10-24 03:42:51 +02:00
parent fda53a0a2a
commit 27ed26d6f2
16 changed files with 24 additions and 31 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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