问题描述
说一个人
有很多 House
和 House
有很多门
。 (因此,门
有一个 house_id
,而众议院有一个 person_id
领域)。我在Active Admin中有一个门列表,其中需要一个过滤器,该过滤器允许我选择一个人,并向我显示该人所有房屋中的所有门。
Say a Person
has many House
and House
has many Door
. (So Door
has a house_id
and House has a person_id
field). I have a list of Doors in Active Admin, in which I want a filter that allows me to choose a person, and show me all doors in all of that person's houses.
ActiveAdmin.register Door do
filter :knob_color
filter :is_open
filter :has_window
filter :house_person # DOESN'T WORK
filter :house_person_name # DOESN'T WORK
Person
模型表具有一个 name
字段,因此ActiveAdmin应该能够选择该字段
The Person
model table has a name
field, so ActiveAdmin should be able to pick that up.
我该怎么做?
根据要求,我的情况在模型中更改。
As requested, my situation rephrased in models.
# id: integer
# name: string
class Person < ActiveRecord::Base
has_many :houses
end
# id: integer
# person_id: integer
class House < ActiveRecord::Base
belongs_to :person
has_many :doors
end
# id: integer
# house_id: integer
# knob_color: string
# is_open: boolean
# has_window: boolean
class Door < ActiveRecord::Base
belongs_to :house
end
推荐答案
您需要使用 has_one 门
上注册人
关联/ code>关系通过 house
,然后您可以直接添加过滤器。
You need to register a person
association on Door
using a has_one
relation through house
, and then you can add the filter directly.
class Door < ActiveRecord::Base
belongs_to :house
has_one :person, through: :house
end
ActiveAdmin.register Door do
filter :person
end
这篇关于两级深归属与关联的活动管理员过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!