1
0

Extract SQL heredoc method for Announcement scopes (#28613)

This commit is contained in:
Matt Jankowski 2024-01-08 06:22:16 -05:00 committed by GitHub
parent aa6d07dbd9
commit 1bc5a52139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,8 @@ class Announcement < ApplicationRecord
scope :unpublished, -> { where(published: false) }
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 :chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) ASC')) }
scope :reverse_chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) DESC')) }
scope :chronological, -> { order(coalesced_chronology_timestamps.asc) }
scope :reverse_chronological, -> { order(coalesced_chronology_timestamps.desc) }
has_many :announcement_mutes, dependent: :destroy
has_many :announcement_reactions, dependent: :destroy
@ -33,6 +33,16 @@ class Announcement < ApplicationRecord
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
text
end