您将不得不推出自己的范围。ActiveAdmin 使用 meta_search 作为其过滤器 (https://github.com/ernie/meta_search)。
在您的管理文件中:
filter :child_id_all,
:as => :check_boxes,
:collection => proc { Child.all }
filter :child_id_all_not,
:as => :check_boxes,
:collection => proc { Child.all }
在您的父模型中:
scope :child_id_all_in, -> ids {
ids.reduce(scoped) do |scope, id|
subquery = Parent.select('`parents`.`id`').
joins(:childs).
where('`childs`.`id` = ?', id)
scope.where("`parents`.`id` IN (#{subquery.to_sql})")
end
}
scope :child_id_all_not_in, -> ids {
ids.reduce(scoped) do |scope, id|
subquery = Parent.select('`parents`.`id`').
joins(:childs).
where('`childs`.`id` = ?', id)
scope.where("`parents`.`id` NOT IN (#{subquery.to_sql})")
end
}
search_methods :child_id_all_in
search_methods :child_id_all_not_in