Skip to content

Commit

Permalink
Explicit table names
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 9, 2023
1 parent d1d6ef2 commit 5a167a5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Episode < ApplicationRecord

MAX_SEGMENT_COUNT = 10
VALID_ITUNES_TYPES = %w[full trailer bonus]
DROP_DATE = "COALESCE(episodes.published_at, episodes.released_at)"

attr_accessor :strict_validations

Expand Down Expand Up @@ -61,10 +62,10 @@ class Episode < ApplicationRecord
scope :draft, -> { where("episodes.published_at IS NULL") }
scope :scheduled, -> { where("episodes.published_at IS NOT NULL AND episodes.published_at > now()") }
scope :draft_or_scheduled, -> { draft.or(scheduled) }
scope :after, ->(time) { where("COALESCE(published_at, released_at) > ?", time) }
scope :after, ->(time) { where("#{DROP_DATE} > ?", time) }
scope :filter_by_title, ->(text) { where("episodes.title ILIKE ?", "%#{text}%") }
scope :dropdate_asc, -> { reorder(Arel.sql("COALESCE(published_at, released_at) ASC NULLS FIRST")) }
scope :dropdate_desc, -> { reorder(Arel.sql("COALESCE(published_at, released_at) DESC NULLS LAST")) }
scope :dropdate_asc, -> { reorder(Arel.sql("#{DROP_DATE} ASC NULLS FIRST")) }
scope :dropdate_desc, -> { reorder(Arel.sql("#{DROP_DATE} DESC NULLS LAST")) }

enum :medium, [:audio, :uncut, :video], prefix: true

Expand Down

0 comments on commit 5a167a5

Please sign in to comment.