Skip to content

Commit 458269a

Browse files
committed
Add config.global_records_identifier configuration
1 parent 7e3bd8a commit 458269a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/acts_as_tenant.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def self.add_global_record_model model
5858
@@models_with_global_records.push(model)
5959
end
6060

61+
def self.global_records_identifier
62+
ActsAsTenant.configuration.global_records_identifier
63+
end
64+
6165
def self.fkey
6266
"#{@@tenant_klass}_id"
6367
end

lib/acts_as_tenant/configuration.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ActsAsTenant
22
class Configuration
3-
attr_writer :require_tenant, :pkey
3+
attr_writer :require_tenant, :pkey, :global_records_identifier
44
attr_reader :tenant_change_hook
55

66
def require_tenant
@@ -11,6 +11,10 @@ def pkey
1111
@pkey ||= :id
1212
end
1313

14+
def global_records_identifier
15+
@global_records_identifier ||= nil
16+
end
17+
1418
def job_scope
1519
@job_scope || ->(relation) { relation.all }
1620
end

lib/acts_as_tenant/model_extensions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def acts_as_tenant(tenant = :account, scope = nil, **options)
2323

2424
if ActsAsTenant.current_tenant
2525
keys = [ActsAsTenant.current_tenant.send(pkey)].compact
26-
keys.push(nil) if options[:has_global_records]
26+
keys.push(ActsAsTenant.global_records_identifier) if options[:has_global_records]
2727

2828
if options[:through]
2929
query_criteria = {options[:through] => {fkey.to_sym => keys}}

0 commit comments

Comments
 (0)