Remove unnecessary foreign_key options

When we specify `belongs_to :author`, ActiveRecord automatically uses
`author_id` as the foreign key.
This commit is contained in:
Javi Martín
2019-10-24 02:38:44 +02:00
parent 904917e568
commit fda53a0a2a
23 changed files with 26 additions and 26 deletions

View File

@@ -32,7 +32,7 @@ class Budget
translates :description, touch: true translates :description, touch: true
include Globalizable 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 :heading
belongs_to :group belongs_to :group
belongs_to :budget belongs_to :budget

View File

@@ -1,5 +1,5 @@
class Budget::Investment::ChangeLog < ApplicationRecord 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 :old_value, presence: true
validates :new_value, presence: true validates :new_value, presence: true

View File

@@ -12,7 +12,7 @@ class Budget
include Sanitizable include Sanitizable
belongs_to :budget 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 has_one :prev_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id
validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH } validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH }

View File

@@ -24,7 +24,7 @@ class Debate < ApplicationRecord
translates :description, touch: true translates :description, touch: true
include Globalizable 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 belongs_to :geozone
has_many :comments, as: :commentable has_many :comments, as: :commentable

View File

@@ -1,6 +1,6 @@
class DirectMessage < ApplicationRecord class DirectMessage < ApplicationRecord
belongs_to :sender, class_name: "User", foreign_key: "sender_id" belongs_to :sender, class_name: "User"
belongs_to :receiver, class_name: "User", foreign_key: "receiver_id" belongs_to :receiver, class_name: "User"
validates :title, presence: true validates :title, presence: true
validates :body, presence: true validates :body, presence: true

View File

@@ -6,7 +6,7 @@ class Legislation::Annotation < ApplicationRecord
serialize :ranges, Array serialize :ranges, Array
belongs_to :draft_version, class_name: "Legislation::DraftVersion", foreign_key: "legislation_draft_version_id" 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 has_many :comments, as: :commentable, dependent: :destroy
validates :text, presence: true validates :text, presence: true

View File

@@ -20,7 +20,7 @@ class Legislation::PeopleProposal < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" 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 has_many :comments, as: :commentable
validates :title, presence: true validates :title, presence: true

View File

@@ -20,7 +20,7 @@ class Legislation::Proposal < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" 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 belongs_to :geozone
has_many :comments, as: :commentable has_many :comments, as: :commentable

View File

@@ -6,7 +6,7 @@ class Legislation::Question < ApplicationRecord
translates :title, touch: true translates :title, touch: true
include Globalizable 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" 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", has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id",

View File

@@ -28,7 +28,7 @@ class Poll < ApplicationRecord
has_many :ballot_sheets has_many :ballot_sheets
has_and_belongs_to_many :geozones 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 :related, polymorphic: true
belongs_to :budget belongs_to :budget

View File

@@ -1,6 +1,6 @@
class Poll::Answer < ApplicationRecord class Poll::Answer < ApplicationRecord
belongs_to :question, -> { with_hidden } 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 delegate :poll, :poll_id, to: :question

View File

@@ -1,8 +1,8 @@
class Poll::PairAnswer < ApplicationRecord class Poll::PairAnswer < ApplicationRecord
belongs_to :question, -> { with_hidden } 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 :answer_right, class_name: "Poll::Question::Answer", foreign_key: "answer_rigth_id" belongs_to :answer_right, class_name: "Poll::Question::Answer"
belongs_to :answer_left, class_name: "Poll::Question::Answer", foreign_key: "answer_left_id" belongs_to :answer_left, class_name: "Poll::Question::Answer"
delegate :poll, :poll_id, to: :question delegate :poll, :poll_id, to: :question

View File

@@ -2,7 +2,7 @@ class Poll::PartialResult < ApplicationRecord
VALID_ORIGINS = %w[web booth] VALID_ORIGINS = %w[web booth]
belongs_to :question, -> { with_hidden } 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 :booth_assignment
belongs_to :officer_assignment belongs_to :officer_assignment

View File

@@ -9,7 +9,7 @@ class Poll::Question < ApplicationRecord
include Globalizable include Globalizable
belongs_to :poll 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 :comments, as: :commentable
has_many :answers, class_name: "Poll::Answer" has_many :answers, class_name: "Poll::Answer"

View File

@@ -9,7 +9,7 @@ class Poll::Question::Answer < ApplicationRecord
accepts_nested_attributes_for :documents, allow_destroy: true 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" has_many :videos, class_name: "Poll::Question::Answer::Video"
validates_translation :title, presence: true validates_translation :title, presence: true

View File

@@ -1,5 +1,5 @@
class Poll::Question::Answer::Video < ApplicationRecord 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\/|\/)([^#\&\?]*).*/ VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/

View File

@@ -1,7 +1,7 @@
class Poll::Recount < ApplicationRecord class Poll::Recount < ApplicationRecord
VALID_ORIGINS = %w[web booth letter].freeze 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 :booth_assignment
belongs_to :officer_assignment belongs_to :officer_assignment

View File

@@ -35,7 +35,7 @@ class Proposal < ApplicationRecord
include Globalizable include Globalizable
translation_class_delegate :retired_at 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 belongs_to :geozone
has_many :comments, as: :commentable, dependent: :destroy has_many :comments, as: :commentable, dependent: :destroy
has_many :proposal_notifications, dependent: :destroy has_many :proposal_notifications, dependent: :destroy

View File

@@ -2,7 +2,7 @@ class ProposalNotification < ApplicationRecord
include Graphqlable include Graphqlable
include Notifiable include Notifiable
belongs_to :author, class_name: "User", foreign_key: "author_id" belongs_to :author, class_name: "User"
belongs_to :proposal belongs_to :proposal
validates :title, presence: true validates :title, presence: true

View File

@@ -5,7 +5,7 @@ class RelatedContent < ApplicationRecord
acts_as_paranoid column: :hidden_at acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases 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 :parent_relationable, polymorphic: true, touch: true
belongs_to :child_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 has_one :opposite_related_content, class_name: "RelatedContent", foreign_key: :related_content_id

View File

@@ -1,6 +1,6 @@
class SignatureSheet < ApplicationRecord class SignatureSheet < ApplicationRecord
belongs_to :signable, polymorphic: true 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] VALID_SIGNABLES = %w[Proposal Budget::Investment]

View File

@@ -4,7 +4,7 @@ class Topic < ApplicationRecord
include Notifiable include Notifiable
belongs_to :community 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 has_many :comments, as: :commentable

View File

@@ -1,6 +1,6 @@
class VotationSetAnswer < ApplicationRecord class VotationSetAnswer < ApplicationRecord
belongs_to :votation_type 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) } scope :by_author, -> (author) { where(author: author) }
end end