如何在Active Admin中的另一个过滤器上添加从一个模型到另一个模型的过滤器或创建自定义过滤器基础

发布于 2025-01-22 08:08:11 字数 935 浏览 0 评论 0原文

class Order < ApplicationRecord
   belongs_to :store, foreign_key: 'Store'
end

class Store < ActiveRecord::Base
   belongs_to :organization, foreign_key: 'OrganizationRef', required: false
end
class Organization < ActiveRecord::Base
  has_many :stores, foreign_key: 'Ref', autosave: true
end

ActiveAdmin.register Order do
   filter :store, collection:
     Store.includes(:organization).references(:organization).collect { |store| 
      [store.organization&.Name, store.Ref] 
    }, as: :searchable_select, multiple: true
end

ActiveAdmin.register Store do
  filter :organization,  :collection => proc {(Organization.all).map{|c| [c.Name, 
                     c.Ref]}} , as: :searchable_select, label: 'Організація'
end

为了使我需要通过组织以顺序创建过滤器 订单 - 有列:参考,存储,..... 商店 - 有列:Ref,EnvisionRef 组织 - 有列:参考,.. 商店与组织之间的关联是 - 'store.organizationref = agrommy.ref'

class Order < ApplicationRecord
   belongs_to :store, foreign_key: 'Store'
end

class Store < ActiveRecord::Base
   belongs_to :organization, foreign_key: 'OrganizationRef', required: false
end
class Organization < ActiveRecord::Base
  has_many :stores, foreign_key: 'Ref', autosave: true
end

ActiveAdmin.register Order do
   filter :store, collection:
     Store.includes(:organization).references(:organization).collect { |store| 
      [store.organization&.Name, store.Ref] 
    }, as: :searchable_select, multiple: true
end

ActiveAdmin.register Store do
  filter :organization,  :collection => proc {(Organization.all).map{|c| [c.Name, 
                     c.Ref]}} , as: :searchable_select, label: 'Організація'
end

In order I need to create filter by organization in Order
Order - has columns: Ref,Store,.....
Store - has columns: Ref, OrganizationRef
Organization - has columns: Ref,..
association between Store and Organization is - 'Store.OrganizationRef = Organization.Ref'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文