Skip to content

Commit b2819c0

Browse files
improve handle class loading
1 parent 3e2f3f1 commit b2819c0

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/active_record/tenanted/cross_tenant_associations.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ def define_enhanced_association(association_type, name, scope, **options)
3535
end
3636

3737
def enhance_cross_tenant_association(name, scope, options)
38-
begin
39-
target_class = options[:class_name]&.constantize || name.to_s.classify.constantize
40-
rescue NameError
41-
# Class not yet loaded during Rails initialization, skip enhancement
42-
return scope
43-
end
38+
target_class = options[:class_name]&.safe_constantize || name.to_s.classify.safe_constantize
39+
40+
return scope unless target_class
4441

4542
unless target_class.tenanted?
4643
tenant_column = options[:tenant_column]

0 commit comments

Comments
 (0)