我的一个模型有一个命名范围,可以正常工作。代码是:
named_scope :inbox_threads, lambda { |user|
{
:include => [:deletion_flags, :recipiences],
:conditions => ["recipiences.user_id = ? AND deletion_flags.user_id IS NULL", user.id],
:group => "msg_threads.id"
}}
这在使用 MySQL 数据库的应用程序的本地副本上运行良好,但是当我将应用程序推送到 Heroku(仅使用 PostgreSQL)时,出现以下错误:
ActiveRecord::StatementInvalid (PGError: ERROR: column "msg_threads.subject" must appear in the GROUP BY clause or be used in an aggregate function:
SELECT "msg_threads"."id" AS t0_r0, "msg_threads"."subject" AS t0_r1, "msg_threads"."originator_id" AS t0_r2, "msg_thr
eads"."created_at" AS t0_r3, "msg_threads"."updated_at" AS t0_r4, "msg_threads"."url_key" AS t0_r5, "deletion_flags"."id" AS t1_r0, "deletion_flags"."user_id" AS t1_r1, "deletion_flags"."msg_thread_id" AS t1_r2, "deletion_flags"."confirmed"
AS t1_r3, "deletion_flags"."created_at" AS t1_r4, "deletion_flags"."updated_at" AS t1_r5, "recipiences"."id" AS t2_r0, "recipiences"."user_id" AS t2_r1, "recipiences"."msg_thread_id" AS t2_r2, "recipiences"."created_at" AS t2_r3, "recipien
ces"."updated_at" AS t2_r4 FROM "msg_threads" LEFT OUTER JOIN "deletion_flags" ON deletion_flags.msg_thread_id = msg_threads.id LEFT OUTER JOIN "recipiences" ON recipiences.msg_thread_id = msg_threads.id WHERE (recipiences.user_id = 1 AND
deletion_flags.user_id IS NULL) GROUP BY msg_threads.id)
我不熟悉 Postgres 的工作,所以我需要在此处添加什么才能使其正常工作?谢谢!