我有以下范围:
scope :this_month, :conditions => ["created_at >= ?", Date.today.beginning_of_month]
这使得 SQL 输出为a.response_sets.this_month.to_sql
:
SELECT "response_sets".* FROM "response_sets" WHERE created_at >= '2012-05-01'
但由于今天实际上是 6 月 1 日,这个日期似乎是错误的。所以,我尝试绕过范围,直接做一个条件,如下所示:
a.response_sets.where(["created_at >= ?", Date.today.beginning_of_month]).to_sql
然后,输出:
SELECT "response_sets".* FROM "response_sets" WHERE created_at >= '2012-06-01'
哪个是对的。Date.today.beginning_of_month
那么为什么在范围内做和直接在范围内做有区别where
呢?