【问题标题】:rails - active admin - PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressionsrails - active admin - PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON 表达式必须匹配初始 ORDER BY 表达式
【发布时间】:2018-11-06 03:50:37
【问题描述】:

我在模型中有一个范围,当我从 rails 控制台调用它时,它工作得非常好,但是当我尝试在活动管理员中使用它时,它会抛出一个错误

这里是范围

scope :clicked, -> { select('distinct on (email_stats.clicked_url) email_stats.*').order(:clicked_url, :action_performed_at)}

这是我尝试在活动管理员中使用它时遇到的错误

ActionView::Template::Error (PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON 表达式必须匹配初始 ORDER BY 表达式 第 1 行:SELECT distinct on (email_stats.clicked_url) email_stats.* ... ^ : SELECT distinct on (email_stats.clicked_url) email_stats.* FROM “email_stats” ORDER BY “email_stats”.“id” desc, “email_stats”.“clicked_url” ASC, “email_stats”.“action_performed_at” ASC LIMIT $1 OFFSET $2):

谁能告诉我我在这里缺少什么?我一直在查看其他帖子,但似乎都没有帮助。

【问题讨论】:

    标签: ruby-on-rails activeadmin


    【解决方案1】:

    尝试在作用域内使用 distinct 可能会有问题。相反,我使用:

    controller do
      def apply_filtering(collection)
        super.distinct
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2012-09-23
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多