0

我有一个名为 的模型Program,它有 'directory_id'、'id'、'user_id' 列,我想按目录选择所有程序组:

@programs = Program.select("programs.directory_id, programs.id, programs.user_id").group(:directory_id).page(params[:page])

错误是:

PG::Error: ERROR:  column "programs.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT  programs.directory_id, programs.id FROM "programs"  ...
                                       ^
: SELECT  programs.directory_id, programs.id FROM "programs"  GROUP BY directory_id LIMIT 25 OFFSET 0
4

0 回答 0