During looking into this I found that scoped search can't search through two has_many :through
relations if they are not in the same model. I redefined role has_many :permissions, :through filterings which seems to work. Then it turned out, for some reason scoped search return wrong results when I use "permission = something" while other operators such as ~ or ^ works just fine. I can't continue with this right now, the patch I put together so far follows
diff --git a/app/models/role.rb b/app/models/role.rb
index 082a82f..b821a9c 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -50,7 +50,9 @@ class Role < ApplicationRecord
has_many :filters, :autosave => true, :dependent => :destroy
- has_many :permissions, :through => :filters
+ # has_many :permissions, :through => :filters
+ has_many :filterings, :through => :filters
+ has_many :permissions, :through => :filterings
has_many :cloned_roles, :class_name => 'Role', :foreign_key => 'cloned_from_id', :dependent => :nullify
belongs_to :cloned_from, :class_name => 'Role'
@@ -70,6 +72,7 @@ class Role < ApplicationRecord
scoped_search :on => :name, :complete_value => true
scoped_search :on => :builtin, :complete_value => { :true => true, :false => false }
scoped_search :on => :description, :complete_value => false
+ scoped_search :on => :name, :relation => :permissions, :complete_value => true, :rename => 'has_permission', :only_explicit => true
def permissions=(new_permissions)
add_permissions(new_permissions.map(&:name).uniq) if new_permissions.present?