acts_as_multi_tenant 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multi_tenant/belongs_to_tenant.rb +5 -2
- data/lib/multi_tenant/proxies_to_tenant.rb +11 -0
- data/lib/multi_tenant/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f798021b2f0d018f7487922f84044db2b9ef1ea6e961ac134fe7cf602774119
|
4
|
+
data.tar.gz: c438ed78359432b8ac602e0c080304b14cf3ed5100e959de379f3d407b6e2a36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cfb7bac41361b0c3c5840ec510e571f513e6addef721f85f5d3f414cd9ba8c943f8de73f105f27b4ef5e88600af63078fbfebeb9d53486c9cecfb4ea30c8c88
|
7
|
+
data.tar.gz: e7406e359b33dd5159ab0f2acfdfab721e1d7dcb5d4717f506cfe77396cd5deb3b6803df7924a45062fc58922197a835ffe8c0c7608c415c465d18a522be362b
|
@@ -61,8 +61,11 @@ module MultiTenant
|
|
61
61
|
# Assign this model to the current tenant (if any). If there are multiple current tenants this is a no-op.
|
62
62
|
#
|
63
63
|
def assign_to_current_tenant
|
64
|
-
|
65
|
-
|
64
|
+
code_col = self.class.tenant_class.tenant_identifier
|
65
|
+
current = self.class.tenant_class.current_tenants
|
66
|
+
|
67
|
+
if current.size == 1 or current.map(&code_col).uniq.size == 1
|
68
|
+
current_tenant_id = self.class.tenant_class.current_tenants.first.send(self.class.tenant_primary_key)
|
66
69
|
send "#{self.class.tenant_foreign_key}=", current_tenant_id
|
67
70
|
end
|
68
71
|
end
|
@@ -61,6 +61,7 @@ module MultiTenant
|
|
61
61
|
self.proxied_tenant_inverse_scope = scope
|
62
62
|
|
63
63
|
extend MultiTenant::ActsAsTenant::TenantGetters
|
64
|
+
extend TenantInterface
|
64
65
|
extend case [ref.macro, ref.inverse_of.macro]
|
65
66
|
when [:has_many, :belongs_to], [:has_one, :belongs_to], [:belongs_to, :has_one]
|
66
67
|
ProxiesToTenantSingularInverseAssociation
|
@@ -79,6 +80,16 @@ module MultiTenant
|
|
79
80
|
respond_to? :proxied_tenant_class
|
80
81
|
end
|
81
82
|
|
83
|
+
#
|
84
|
+
# Class methods to give this the same interface as a "real" tenant class.
|
85
|
+
#
|
86
|
+
module TenantInterface
|
87
|
+
# Returns the tenant_identifier from the proxied class
|
88
|
+
def tenant_identifier
|
89
|
+
self.proxied_tenant_class.tenant_identifier
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
82
93
|
#
|
83
94
|
# Class methods for tenant proxies that have a singular inverse association (i.e. belongs_to or has_one).
|
84
95
|
#
|
data/lib/multi_tenant/version.rb
CHANGED