@@ -6,15 +6,6 @@ module CrossTenantAssociations
66 extend ActiveSupport ::Concern
77
88 class_methods do
9- # I think we can have more configs later
10- def cross_tenant_config ( **config )
11- @cross_tenant_config = config
12- end
13-
14- def get_cross_tenant_config
15- @cross_tenant_config ||= { }
16- end
17-
189 def has_one ( name , scope = nil , **options )
1910 define_enhanced_association ( :has_one , name , scope , **options )
2011 end
@@ -26,9 +17,8 @@ def has_many(name, scope = nil, **options)
2617 private
2718 # For now association methods are identical
2819 def define_enhanced_association ( association_type , name , scope , **options )
29- config = get_cross_tenant_config
30- tenant_column = config [ :tenant_column ] || :tenant_id
31- custom_options = options . merge ( tenant_column : tenant_column )
20+ tenant_key = options . delete ( :tenant_key )
21+ custom_options = { tenant_key : tenant_key || :tenant_id }
3222
3323 enhanced_scope = enhance_cross_tenant_association ( name , scope , custom_options )
3424 method ( association_type ) . super_method . call ( name , enhanced_scope , **options )
@@ -40,11 +30,11 @@ def enhance_cross_tenant_association(name, scope, options)
4030 return scope unless target_class
4131
4232 unless target_class . tenanted?
43- tenant_column = options [ :tenant_column ]
33+ tenant_key = options [ :tenant_key ]
4434
4535 return -> ( record ) {
4636 base_scope = scope ? target_class . instance_exec ( &scope ) : target_class . all
47- base_scope . where ( tenant_column => record . tenant )
37+ base_scope . where ( tenant_key => record . tenant )
4838 }
4939 end
5040
0 commit comments