Skip to content

Commit

Permalink
Fix condition within scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmir committed Jan 23, 2025
1 parent 47f2d12 commit c086208
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/meeting/app/models/scheduled_meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ class ScheduledMeeting < ApplicationRecord
belongs_to :recurring_meeting

scope :upcoming, -> {
if instantiated
joins(:meeting).where("scheduled_meetings.start_time + (interval '1 hour' * meetings.duration) >= ?", Time.current)
if instantiated?
joins(:meeting)
.where("scheduled_meetings.start_time + (interval '1 hour' * meetings.duration) >= ?", Time.current)
else
where(start_time: Time.current..)
end
}
scope :past, -> {
if instantiated
if instantiated?
joins(:meeting)
.where("scheduled_meetings.start_time + (interval '1 hour' * meetings.duration) < ?", Time.current)
else
Expand All @@ -56,4 +57,8 @@ class ScheduledMeeting < ApplicationRecord

validates_uniqueness_of :meeting, allow_nil: true
validates_presence_of :start_time

def self.instantiated?
any?(&:meeting_id)
end
end

0 comments on commit c086208

Please sign in to comment.