0
votes

I can successfully create a scope to find objects where a date falls in a range -

all_matches = Person.where({
  :some_date.gte => first_date,
  :some_date.lte => last_date
})

But when I use or instead of where it starts returning data that doesn't match any of the criteria -

all_matches = Person.or({
  :some_date.gte => first_date,
  :some_date.lte => last_date
}, {
  :some_other_date.gte => first_date,
  :some_other_date.lte => last_date
})

I don't see any reason for this, I've been using or before but with single values not ranges.

1

1 Answers

0
votes

Is your intention is to get all persons with some_date or some_other_date in range between first_date and last_date. If that is true try:

first_date, last_date = [Time.now.to_date, (Time.now + 1.day).to_date]
Person.or(
    {:some_date => first_date..last_date},
    {:some_other_date => first_date..last_date}
)

Hope it helps.