[英]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.