简体   繁体   English

rails-活动管理员-PG :: InvalidColumnReference:错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配

[英]rails - active admin - PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions

I have a scope in a Model which works perfectly fine when I call it from rails console but when I try to use it in active admin it throws an error 我在模型中有一个作用域,当我从Rails控制台调用它时可以很好地工作,但是当我尝试在活动admin中使用它时会抛出错误

Here is the scope 这是范围

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

Here is the error i get when i try to use it in active admin 这是我在主动管理员中尝试使用它时遇到的错误

ActionView::Template::Error (PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions LINE 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): ActionView :: Template :: Error(PG :: InvalidColumnReference:错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配LINE 1:SELECT单独于(email_stats.clicked_url)email_stats。* ... ^:SELECT单独于(email_stats。 *从“ email_stats”订购,按“ email_stats”订购。“ id” desc,“ email_stats”。“ clicked_url” ASC,“ email_stats”。“ action_performed_at” ASC限制$ 1抵消$ 2):

Could anyone please let me know what am i missing here? 有人可以让我知道我在这里想念什么吗? I have been looking into other posts but none of them seem helpful. 我一直在寻找其他职位,但似乎都没有帮助。

Trying to use distinct inside the scope may be problematic. 试图在范围内使用不同的内容可能会有问题。 Instead I use: 相反,我使用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PG::InvalidColumnReference: 错误:对于 SELECT DISTINCT,ORDER BY 表达式必须出现在选择列表中 - PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list 错误:SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配 - ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions SELECT DISTINCT ON表达式必须与初始ORDER BY表达式匹配 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions PG::Error: SELECT DISTINCT,ORDER BY 表达式必须出现在 select 列表中 - PG::Error: SELECT DISTINCT, ORDER BY expressions must appear in select list Active Record&Rails:错误:对于SELECT DISTINCT,ORDER BY表达式必须出现在选择列表中 - Active Record & Rails: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list SELECT DISTINCT的PG错误,ORDER BY表达式在尝试在Heroku上查看时必须出现在选择列表中 - PG error for SELECT DISTINCT, ORDER BY expressions must appear in select list when trying to view on Heroku 错误:对于 SELECT DISTINCT,ORDER BY 表达式必须使用 order by 和 uniq 出现在选择列表中 - ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list using order by with uniq 如何解决“对于SELECT DISTINCT,ORDER BY表达式必须出现在选择列表中”错误 - How to solve “for SELECT DISTINCT, ORDER BY expressions must appear in select list” error PG :: InvalidColumnReference:按关联表排序时出错 - PG::InvalidColumnReference: ERROR when sorting by associated table Rails Active Record 等效于带有条件表达式的 SQL - Rails Active Record equivalent of SQL with conditional expressions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM