Skip to content

Commit 5c1cfff

Browse files
committed
prepend ActiveRecordRelationExtension only when model supports multi-tenant
1 parent 3b21347 commit 5c1cfff

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/activerecord-multi-tenant/relation_extension.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ module Arel
44
module ActiveRecordRelationExtension
55
# Overrides the delete_all method to include tenant scoping
66
def delete_all
7+
model = MultiTenant.multi_tenant_model_for_arel(arel)
8+
79
# Call the original delete_all method if the current tenant is identified by an ID
8-
return super if MultiTenant.current_tenant_is_id? || MultiTenant.current_tenant.nil?
10+
return super if model.nil? || MultiTenant.current_tenant_is_id? || MultiTenant.current_tenant.nil?
911

1012
stmt = Arel::DeleteManager.new.from(table)
1113
stmt.wheres = [generate_in_condition_subquery]
@@ -16,8 +18,10 @@ def delete_all
1618

1719
# Overrides the update_all method to include tenant scoping
1820
def update_all(updates)
21+
model = MultiTenant.multi_tenant_model_for_arel(arel)
22+
1923
# Call the original update_all method if the current tenant is identified by an ID
20-
return super if MultiTenant.current_tenant_is_id? || MultiTenant.current_tenant.nil?
24+
return super if model.nil? || MultiTenant.current_tenant_is_id? || MultiTenant.current_tenant.nil?
2125

2226
stmt = Arel::UpdateManager.new
2327
stmt.table(table)

0 commit comments

Comments
 (0)