Rails groupdate gem pg错误

时间:2014-10-10 13:13:00

标签: ruby-on-rails-3 activerecord scope

我有一个Rails 3.2.14应用程序,我试图使用chartkickgroupdate gem来生成一些图表。我已经安装了两个宝石,并且我试图在Call模型的控制台上进行一些测试查询。

Call.group_by_day(:created_at)

我引发异常并收到以下错误:

 Call Load (8.8ms)  SELECT "calls".* FROM "calls" WHERE (created_at IS NOT NULL) GROUP BY (DATE_TRUNC('week', (created_at::timestamptz - INTERVAL '6 day' - INTERVAL '0' hour) AT TIME ZONE 'America/Chicago') + INTERVAL '6 day' + INTERVAL '0' hour) AT TIME ZONE 'America/Chicago'
ActiveRecord::StatementInvalid: PG::Error: ERROR:  column "calls.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "calls".* FROM "calls"  WHERE (created_at IS NOT NULL...
               ^
: SELECT "calls".* FROM "calls"  WHERE (created_at IS NOT NULL) GROUP BY (DATE_TRUNC('week', (created_at::timestamptz - INTERVAL '6 day' - INTERVAL '0' hour) AT TIME ZONE 'America/Chicago') + INTERVAL '6 day' + INTERVAL '0' hour) AT TIME ZONE 'America/Chicago

我是否应该做些什么来使这项工作?我需要创建某种范围才能使其工作吗?我对宝石很陌生,所以任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

显然我没有正确地调用它。

我需要致电Call.group_by_day(:created_at).count来完成这项工作。