我有选择班次的余地:
scope :by_date, lambda { |date|
where "end_date BETWEEN ? AND ? OR start_date BETWEEN ? AND ?", date.beginning_of_day, date.end_of_day, date.beginning_of_day, date.end_of_day
}
是更清洁的方法吗?
我有选择班次的余地:
scope :by_date, lambda { |date|
where "end_date BETWEEN ? AND ? OR start_date BETWEEN ? AND ?", date.beginning_of_day, date.end_of_day, date.beginning_of_day, date.end_of_day
}
是更清洁的方法吗?
scope :by_date, lambda { |date|
where("DATE(start_date) = :date OR DATE(end_date) = :date", date: date.to_date)
}
这个怎么样:
scope :by_date, lambda { |date|
where("end_date BETWEEN :beginning AND :end OR start_date BETWEEN :beginning AND :end",
beginning: date.beginning_of_day, end: date.end_of_day)
}