From 217ef99678f24b13cfef1cd00bb41f14a9d9f93c Mon Sep 17 00:00:00 2001 From: Lucas Zhang Date: Wed, 10 Jan 2024 10:06:59 +0800 Subject: [PATCH] Support global_records_identifier configuration --- lib/acts_as_tenant/configuration.rb | 6 +++++- lib/acts_as_tenant/model_extensions.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/acts_as_tenant/configuration.rb b/lib/acts_as_tenant/configuration.rb index e75ebcfc..a9ea9e3c 100644 --- a/lib/acts_as_tenant/configuration.rb +++ b/lib/acts_as_tenant/configuration.rb @@ -1,6 +1,6 @@ module ActsAsTenant class Configuration - attr_writer :require_tenant, :pkey + attr_writer :require_tenant, :pkey, :global_records_identifier def require_tenant @require_tenant ||= false @@ -10,6 +10,10 @@ def pkey @pkey ||= :id end + def global_records_identifier + @global_records_identifier ||= nil + end + def job_scope @job_scope || ->(relation) { relation.all } end diff --git a/lib/acts_as_tenant/model_extensions.rb b/lib/acts_as_tenant/model_extensions.rb index 053b9b85..9c253feb 100644 --- a/lib/acts_as_tenant/model_extensions.rb +++ b/lib/acts_as_tenant/model_extensions.rb @@ -23,7 +23,7 @@ def acts_as_tenant(tenant = :account, scope = nil, **options) if ActsAsTenant.current_tenant keys = [ActsAsTenant.current_tenant.send(pkey)].compact - keys.push(nil) if options[:has_global_records] + keys.push(ActsAsTenant.global_records_identifier) if options[:has_global_records] if options[:through] query_criteria = {options[:through] => {fkey.to_sym => keys}}