Sql rails 4中不推荐的计数

Sql rails 4中不推荐的计数,sql,ruby-on-rails,Sql,Ruby On Rails,我如何在Rails 4中编写这个 这将生成错误: 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中编写这个

这将生成错误:

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'))")
弃用警告:关系#使用查找器选项计算已弃用。请构建一个作用域,然后对其调用calculate。(从at/Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11中的块(2级)调用)
弃用警告:“关系#计数”的:distinct选项已弃用。请改用'Relation#distinct'。(例如,`relation.distinct.count`)。(从at/Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11中的块(2级)调用)
您可以尝试以下方法:

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路

Session.where(:date_at => date_from..date_to)
       .select('user_id').distinct
       .group("date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))")
       .count
@Michael“不推荐使用查找器选项进行计算”意味着您不能进行
count(“…”,:group=>“…”)
。您必须使用
.group(“…”).count来代替。第二个弃用警告是显而易见的。它清楚地说明了你必须做什么。
Session.where(date_at: date_from..date_to).select('distinct user_id')
       .group("date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))").count