I have the following scopes defined in my model:
scope :upcoming, -> { where(:start_time.gt => Time.now).asc(:start_time) }
scope :in_progress, -> {
now = Time.now
where(:start_time.lte => now).where(:end_time.gte => now).asc(:start_time)
}
I want to create another scope that combines the results of both of those scopes called current. I tried something like this:
scope :current, -> { self.in_progress | self.upcoming }
But this just ends up treating them both like arrays and concatenating them. The problem with this is that when I try to call my scope with Model.current, I get the following error message:
NoMethodError: undefined method `as_conditions' for #<Array:0xaceb008>
This is because it converted the Mongoid Criteria object to an array, but I don't want that. I want the object to stay as a Mongoid Criteria object.
What I really want is the union of the in_progress set and the upcoming set.
Any ideas? Thanks.
:$or
query. – Prau