我可以成功创建一个作用域来查找日期落在某个范围内的对象-
all_matches = Person.where({
:some_date.gte => first_date,
:some_date.lte => last_date
})
但是当我使用or
而不是where
时,它开始返回不匹配任何条件的数据-
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
})
我看不出有任何原因,我以前一直在使用or
,但使用单个值而不是范围。
您的目的是获得first_date和last_date之间的some_date或some_other_date范围内的所有人员。如果是真的,试试:
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}
)
希望能有所帮助。