Add missing has_many relations for users
Usually when we specify a `belongs_to` relations, we also specify its equivalent `has_many`. That allows us to write, for example: `topic.user.topics`.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class Activity < ApplicationRecord
|
class Activity < ApplicationRecord
|
||||||
belongs_to :actionable, -> { with_hidden }, polymorphic: true
|
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]
|
VALID_ACTIONS = %w[hide block restore valuate email]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class Budget::Investment::ChangeLog < ApplicationRecord
|
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 :old_value, presence: true
|
||||||
validates :new_value, presence: true
|
validates :new_value, presence: true
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Legislation::Annotation < ApplicationRecord
|
|||||||
serialize :ranges, Array
|
serialize :ranges, Array
|
||||||
|
|
||||||
belongs_to :draft_version, foreign_key: "legislation_draft_version_id"
|
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
|
has_many :comments, as: :commentable, dependent: :destroy
|
||||||
|
|
||||||
validates :text, presence: true
|
validates :text, presence: true
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Legislation::Proposal < ApplicationRecord
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|
||||||
belongs_to :process, foreign_key: "legislation_process_id"
|
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
|
belongs_to :geozone
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :legislation_questions
|
||||||
belongs_to :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",
|
has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id",
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :polls
|
||||||
belongs_to :related, polymorphic: true
|
belongs_to :related, polymorphic: true
|
||||||
belongs_to :budget
|
belongs_to :budget
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_answers
|
||||||
|
|
||||||
delegate :poll, :poll_id, to: :question
|
delegate :poll, :poll_id, to: :question
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
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"
|
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_right, class_name: "Poll::Question::Answer"
|
||||||
belongs_to :answer_left, class_name: "Poll::Question::Answer"
|
belongs_to :answer_left, class_name: "Poll::Question::Answer"
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_partial_results
|
||||||
belongs_to :booth_assignment
|
belongs_to :booth_assignment
|
||||||
belongs_to :officer_assignment
|
belongs_to :officer_assignment
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_questions
|
||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :answers, class_name: "Poll::Answer"
|
has_many :answers, class_name: "Poll::Answer"
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_recounts
|
||||||
belongs_to :booth_assignment
|
belongs_to :booth_assignment
|
||||||
belongs_to :officer_assignment
|
belongs_to :officer_assignment
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :topics
|
||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,12 @@ class User < ApplicationRecord
|
|||||||
has_many :debates, -> { with_hidden }, foreign_key: :author_id
|
has_many :debates, -> { with_hidden }, foreign_key: :author_id
|
||||||
has_many :proposals, -> { 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 :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_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 :comments, -> { with_hidden }
|
||||||
has_many :failed_census_calls
|
has_many :failed_census_calls
|
||||||
has_many :notifications
|
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 :legislation_answers, class_name: "Legislation::Answer", dependent: :destroy, inverse_of: :user
|
||||||
has_many :follows
|
has_many :follows
|
||||||
has_many :budget_rol_assignments
|
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 :budgets, through: :budget_rol_assignments
|
||||||
has_many :votation_set_answers
|
has_many :votation_set_answers
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
|
|||||||
Reference in New Issue
Block a user