Ruby 关于 Rails ActiveAdmin 中的自定义资源检索
Ruby on Rails Custom Resource Retrieval in ActiveAdmin
我有一个页面,我想在其中自定义该页面的整个默认 sql 语句。因此,与此处活动管理文档中的示例不同:https://activeadmin.info/2-resource-customization.html#customizing-resource-retrieval 他们只是添加一个条件,我希望能够执行自定义 sql 语句。这可能吗?
我希望显示的 table 由以下 SQL 语句建模
select driver_id, order_type_cd, start_region, ARRAY_AGG(region_id) from driver_region_preferences group by driver_id, order_type_cd, start_region;
如有任何见解,我们将不胜感激!
将此添加到 admin/driver_region_preference.rb
controller do
def scoped_collection
end_of_association_chain.select('driver_id, order_type_cd, start_region, ARRAY_AGG(region_id)').group('driver_id, order_type_cd, start_region')
end
end
但要注意分组,它在某些数据库上的工作方式不同。
我有一个页面,我想在其中自定义该页面的整个默认 sql 语句。因此,与此处活动管理文档中的示例不同:https://activeadmin.info/2-resource-customization.html#customizing-resource-retrieval 他们只是添加一个条件,我希望能够执行自定义 sql 语句。这可能吗?
我希望显示的 table 由以下 SQL 语句建模
select driver_id, order_type_cd, start_region, ARRAY_AGG(region_id) from driver_region_preferences group by driver_id, order_type_cd, start_region;
如有任何见解,我们将不胜感激!
将此添加到 admin/driver_region_preference.rb
controller do
def scoped_collection
end_of_association_chain.select('driver_id, order_type_cd, start_region, ARRAY_AGG(region_id)').group('driver_id, order_type_cd, start_region')
end
end
但要注意分组,它在某些数据库上的工作方式不同。