如何在Active Admin中的另一个过滤器上添加从一个模型到另一个模型的过滤器或创建自定义过滤器基础
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论