How to add filter from one model to another model or create custom filter base on another filter in active admin

Viewed 36
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'

0 Answers
Related