ruby-on-rails - rails - active admin - PG::InvalidColumnReference: ERROR: SELECT DISTINCT ON 表达式必须匹配初始 ORDER BY 表达式
问题描述
我在模型中有一个范围,当我从 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 表达式 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):
谁能让我知道我在这里缺少什么?我一直在寻找其他帖子,但它们似乎都没有帮助。
解决方案
尝试在范围内使用 distinct 可能会有问题。相反,我使用:
controller do
def apply_filtering(collection)
super.distinct
end
end
推荐阅读
- reactjs - 如何使用 const 在 .js 中创建一个数组,以便我可以使用该数组来创建一行卡片?
- woocommerce - 自定义 Woocommerce 循环查询
- javascript - 如何将 Element 绑定到不同名称的片段?[SAPUI5]
- antd - 如何在 Antd Table 中将多个数据显示到单个列/单元格中?
- excel - 使用 ActiveCell.Row 时出现类型不匹配错误
- css - 如何在使用 Material UI 的 React 中设置全局字体颜色
- python - TensorFlow 自定义过滤层定义,如 glcm 或 gabor
- flutter - 使用 VS 代码颤动,无法找到 Android Studio 可执行文件
- python - 'str' 对象没有属性 'passengerName' - 使用内置 Python 函数
- firebase - 将 Firebase 与 NativeScript 连接起来