Ruby on rails 如何获取离开日期为零或应该在rails中特定日期范围内的记录?
我想在Ruby on rails 如何获取离开日期为零或应该在rails中特定日期范围内的记录?,ruby-on-rails,date-range,Ruby On Rails,Date Range,我想在employee模型上编写一个query,其中employee离开日期为nil,或者应该在特定的日期范围内 以下是我当前的查询: e = Employee.where.not('date_of_leaving >= ? and date_of_leaving <= ?', Date.today - 60, Date.today).where(:date_of_leaving => nil) e=Employee.where.not('date\u of_leaving>
employee
模型上编写一个query
,其中employee
离开日期为nil
,或者应该在特定的日期范围内
以下是我当前的查询:
e = Employee.where.not('date_of_leaving >= ? and date_of_leaving <= ?', Date.today - 60, Date.today).where(:date_of_leaving => nil)
e=Employee.where.not('date\u of_leaving>=?date\u of_leaving以下查询将返回所有在指定日期之间或nil
有date\u of_leaving
的员工:
Employee.where('date_of_leaving BETWEEN ? AND ? OR date_of_leaving IS NULL', Date.today - 60, Date.today)
其中链接是和。有关正确的查询,请参阅@Andrey Deineko的答案