6
a = Session.where(:date_at => date_from..date_to).
            order("date_at").
            count("DISTINCT(user_id)",
                  :group => "date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))")

我怎样才能在 Rails 4 中写这个?

这会产生错误:

DEPRECATION WARNING: Relation#calculate with finder options is deprecated. Please build a scope and then call calculate on it instead. (called from block (2 levels) in <top (required)> at /Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11)
DEPRECATION WARNING: The :distinct option for `Relation#count` is deprecated. Please use `Relation#distinct` instead. (eg. `relation.distinct.count`). (called from block (2 levels) in <top (required)> at /Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11)
4

2 回答 2

9

更多铁轨 4 路。.

Session.where(date_at: date_from..date_to).select('distinct user_id')
       .group("date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))").count
于 2013-08-28T13:12:54.260 回答
2

你可以试试这个:

Session.where(:date_at => date_from..date_to)
       .select('user_id').distinct
       .group("date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))")
       .count
于 2013-08-28T13:09:40.480 回答