Group common `class_name` options in associations (#28779)
parent
da31792ac7
commit
aaa6f2e930
|
@ -20,8 +20,11 @@ class Appeal < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
|
belongs_to :strike, class_name: 'AccountWarning', foreign_key: 'account_warning_id', inverse_of: :appeal
|
||||||
belongs_to :approved_by_account, class_name: 'Account', optional: true
|
|
||||||
belongs_to :rejected_by_account, class_name: 'Account', optional: true
|
with_options class_name: 'Account', optional: true do
|
||||||
|
belongs_to :approved_by_account
|
||||||
|
belongs_to :rejected_by_account
|
||||||
|
end
|
||||||
|
|
||||||
validates :text, presence: true, length: { maximum: 2_000 }
|
validates :text, presence: true, length: { maximum: 2_000 }
|
||||||
validates :account_warning_id, uniqueness: true
|
validates :account_warning_id, uniqueness: true
|
||||||
|
|
|
@ -21,8 +21,10 @@ class EmailDomainBlock < ApplicationRecord
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
include Paginable
|
include Paginable
|
||||||
|
|
||||||
belongs_to :parent, class_name: 'EmailDomainBlock', optional: true
|
with_options class_name: 'EmailDomainBlock' do
|
||||||
has_many :children, class_name: 'EmailDomainBlock', foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
belongs_to :parent, optional: true
|
||||||
|
has_many :children, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||||
|
end
|
||||||
|
|
||||||
validates :domain, presence: true, uniqueness: true, domain: true
|
validates :domain, presence: true, uniqueness: true, domain: true
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,11 @@ class Poll < ApplicationRecord
|
||||||
belongs_to :status
|
belongs_to :status
|
||||||
|
|
||||||
has_many :votes, class_name: 'PollVote', inverse_of: :poll, dependent: :delete_all
|
has_many :votes, class_name: 'PollVote', inverse_of: :poll, dependent: :delete_all
|
||||||
has_many :voters, -> { group('accounts.id') }, through: :votes, class_name: 'Account', source: :account
|
|
||||||
has_many :local_voters, -> { group('accounts.id').merge(Account.local) }, through: :votes, class_name: 'Account', source: :account
|
with_options class_name: 'Account', source: :account, through: :votes do
|
||||||
|
has_many :voters, -> { group('accounts.id') }
|
||||||
|
has_many :local_voters, -> { group('accounts.id').merge(Account.local) }
|
||||||
|
end
|
||||||
|
|
||||||
has_many :notifications, as: :activity, dependent: :destroy
|
has_many :notifications, as: :activity, dependent: :destroy
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,12 @@ class Report < ApplicationRecord
|
||||||
rate_limit by: :account, family: :reports
|
rate_limit by: :account, family: :reports
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :target_account, class_name: 'Account'
|
|
||||||
belongs_to :action_taken_by_account, class_name: 'Account', optional: true
|
with_options class_name: 'Account' do
|
||||||
belongs_to :assigned_account, class_name: 'Account', optional: true
|
belongs_to :target_account
|
||||||
|
belongs_to :action_taken_by_account, optional: true
|
||||||
|
belongs_to :assigned_account, optional: true
|
||||||
|
end
|
||||||
|
|
||||||
has_many :notes, class_name: 'ReportNote', inverse_of: :report, dependent: :destroy
|
has_many :notes, class_name: 'ReportNote', inverse_of: :report, dependent: :destroy
|
||||||
has_many :notifications, as: :activity, dependent: :destroy
|
has_many :notifications, as: :activity, dependent: :destroy
|
||||||
|
|
|
@ -59,8 +59,10 @@ class Status < ApplicationRecord
|
||||||
belongs_to :conversation, optional: true
|
belongs_to :conversation, optional: true
|
||||||
belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true, inverse_of: false
|
belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true, inverse_of: false
|
||||||
|
|
||||||
belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true
|
with_options class_name: 'Status', optional: true do
|
||||||
belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true
|
belongs_to :thread, foreign_key: 'in_reply_to_id', inverse_of: :replies
|
||||||
|
belongs_to :reblog, foreign_key: 'reblog_of_id', inverse_of: :reblogs
|
||||||
|
end
|
||||||
|
|
||||||
has_many :favourites, inverse_of: :status, dependent: :destroy
|
has_many :favourites, inverse_of: :status, dependent: :destroy
|
||||||
has_many :bookmarks, inverse_of: :status, dependent: :destroy
|
has_many :bookmarks, inverse_of: :status, dependent: :destroy
|
||||||
|
|
Loading…
Reference in New Issue