1

当我将Sqlite3更改为PostgreSQL时出现了这个问题。好像我在使用 postgres 时不能使用组方法。

> Post.group(:user_id).all

Post Load (74.2ms)  SELECT "posts".* FROM "posts" GROUP BY user_id
PG::Error: ERROR:  column "posts.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "posts".* FROM "posts"  GROUP BY user_id

是否可以使用等效查询来避免硬编码 SQL 并利用优雅的 AR 方法的好处?

4

0 回答 0