mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-25 12:34:58 +01:00
Extract SQL heredoc method for Announcement scopes (#28613)
This commit is contained in:
parent
aa6d07dbd9
commit
1bc5a52139
@ -21,8 +21,8 @@ class Announcement < ApplicationRecord
|
|||||||
scope :unpublished, -> { where(published: false) }
|
scope :unpublished, -> { where(published: false) }
|
||||||
scope :published, -> { where(published: true) }
|
scope :published, -> { where(published: true) }
|
||||||
scope :without_muted, ->(account) { joins("LEFT OUTER JOIN announcement_mutes ON announcement_mutes.announcement_id = announcements.id AND announcement_mutes.account_id = #{account.id}").where(announcement_mutes: { id: nil }) }
|
scope :without_muted, ->(account) { joins("LEFT OUTER JOIN announcement_mutes ON announcement_mutes.announcement_id = announcements.id AND announcement_mutes.account_id = #{account.id}").where(announcement_mutes: { id: nil }) }
|
||||||
scope :chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) ASC')) }
|
scope :chronological, -> { order(coalesced_chronology_timestamps.asc) }
|
||||||
scope :reverse_chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) DESC')) }
|
scope :reverse_chronological, -> { order(coalesced_chronology_timestamps.desc) }
|
||||||
|
|
||||||
has_many :announcement_mutes, dependent: :destroy
|
has_many :announcement_mutes, dependent: :destroy
|
||||||
has_many :announcement_reactions, dependent: :destroy
|
has_many :announcement_reactions, dependent: :destroy
|
||||||
@ -33,6 +33,16 @@ class Announcement < ApplicationRecord
|
|||||||
|
|
||||||
before_validation :set_published, on: :create
|
before_validation :set_published, on: :create
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def coalesced_chronology_timestamps
|
||||||
|
Arel.sql(
|
||||||
|
<<~SQL.squish
|
||||||
|
COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at)
|
||||||
|
SQL
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def to_log_human_identifier
|
def to_log_human_identifier
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user