簡體   English   中英

ActiveAdmin中的Ruby on Rails定制資源檢索

[英]Ruby on Rails Custom Resource Retrieval in ActiveAdmin

我有一個頁面,我想在其中自定義頁面的整個默認sql語句。 因此,與此處的活動管理文檔中的示例不同: https : //activeadmin.info/2-resource-customization.html#customizing-resource-retrieval他們只是在其中添加條件,我希望能夠執行自定義sql語句。 那可能嗎?

我要顯示的表由以下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

但是請注意分組,它在某些數據庫上的工作方式有所不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM