1

我是初学者。

我的模型:

class Publisher < ActiveRecord::Base
  has_many :articles
  has_many :transactions, through: :articles
  has_many :reader_profiles, -> { uniq }, through: :transactions
  #etc
end

我的导致错误的代码:

@profiles = publisher.reader_profiles

我的错误:

PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ... $1  ORDER BY reader_profiles.transactions_count, transactio...
                                                             ^
: SELECT  DISTINCT "reader_profiles".* FROM "reader_profiles" INNER JOIN "transactions" ON "reader_profiles"."id" = "transactions"."reader_profile_id" INNER JOIN "articles" ON "transactions"."article_id" = "articles"."id" WHERE "articles"."publisher_id" = $1  ORDER BY reader_profiles.transactions_count, transactions.created_at LIMIT 10 OFFSET 0

我的问题:

我显然需要将这些transactions字段添加到我的 SELECT 语句中。我该怎么做?我是否必须JOIN手动插入所有的 s 等?

4

0 回答 0