gpt4 book ai didi

ruby-on-rails - 为什么 Active Admin 不能正确排序这个关联列

转载 作者:行者123 更新时间:2023-12-04 07:29:39 25 4
gpt4 key购买 nike

很难让活跃的管理员对关联的子列进行排序。我有一个包含相关“用户”的个人资料。

ActiveAdmin.register Profile, as: "Member" do

def scoped_collection
end_of_association_chain.includes(:user)
end

column "Referral", sortable: 'user.referrals' do |member|
member.user.referrals
end

--error when sorting---

PG::Error: ERROR: syntax error at or near "."
LINE 1: ... "users"."id" = "profiles"."user_id" ORDER BY user.referrals...
^
: SELECT "profiles"."id" AS t0_r0, "profiles"."actor_id" AS t0_r1,

最佳答案

它给出了 SQL 错误,因为表“user”不存在(预期的表可能是“users”,复数)。

您需要使用以下可排序选项:

# Note sortable is using the plural form of users.
column "Referral", sortable: 'users.referrals' do |member|
member.user.referrals
end

在连接表的列上排序时,它采用 "table_name.column" 的形式。

关于ruby-on-rails - 为什么 Active Admin 不能正确排序这个关联列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19552317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com