I have a rails model Thing
that uses acts_as_tenant
to tie it to a company. This works fine, and now users who are part of a company can only access the Things associated with their company.
class Thing < ApplicationRecord
acts_as_tenant(:company)
belongs_to :company
end
Now I've added an is_global
boolean field to my Thing. Now I would like for Thing (via acts_as_tenant) to instead be scoped such that users have access to their company's Things and any global Things. Is there a way to configure acts_as_tenant
to enable this kind of behavior?
My current workaround is to abandon the acts_as_tenant(:company)
call in this model and instead create a new default scope:
default_scope { where('company_id = ? or is_global = true', ActsAsTenant.current_tenant.id) }
This seems to do the job, though I am concerned that I may be unknowingly bypassing some of the good features of acts_as_tenant here.