0
나는 다음과 같은 범위를 가지고 : a.response_sets.this_month.to_sql
의 SQL 출력을하게날짜와 범위는 일관성이
scope :this_month, :conditions => ["created_at >= ?", Date.today.beginning_of_month]
:
SELECT "response_sets".* FROM "response_sets" WHERE created_at >= '2012-05-01'
을하지만 오늘 6 월 1 일 실제로 때문에, 그 날짜가 잘못된 것 같다. 그래서, 범위를 우회 시도하고 너무 같은 직접 조건을 수행 : 올바른
SELECT "response_sets".* FROM "response_sets" WHERE created_at >= '2012-06-01'
입니다 : 다음, 출력
a.response_sets.where(["created_at >= ?", Date.today.beginning_of_month]).to_sql
합니다. 그렇다면 범위에서 을 수행하고 where
에서 직접 수행하는 것의 차이점은 무엇입니까?
scope :this_month, -> { where("created_at >= ?", Date.today.beginning_of_month) }
완벽한 : 범위의 날짜로 작업 할 때 – Shpigford