|
1 |
| -require_relative './multi_tenant' |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative 'multi_tenant' |
2 | 4 |
|
3 | 5 | module MultiTenant
|
4 | 6 | # Extension to the model to allow scoping of models to the current tenant. This is done by adding
|
5 | 7 | # the multitenant method to the models that need to be scoped. This method is called in the
|
6 | 8 | # model declaration.
|
7 | 9 | # Adds scoped_by_tenant? partition_key, primary_key and inherited methods to the model
|
8 | 10 | module ModelExtensionsClassMethods
|
9 |
| - DEFAULT_ID_FIELD = 'id'.freeze |
| 11 | + DEFAULT_ID_FIELD = 'id' |
10 | 12 | # executes when multi_tenant method is called in the model. This method adds the following
|
11 | 13 | # methods to the model that calls it.
|
12 | 14 | # scoped_by_tenant? - returns true if the model is scoped by tenant
|
@@ -188,17 +190,21 @@ def inherited(subclass)
|
188 | 190 | end
|
189 | 191 |
|
190 | 192 | # skips statement caching for classes that is Multi-tenant or has a multi-tenant relation
|
191 |
| -class ActiveRecord::Associations::Association |
192 |
| - alias skip_statement_cache_orig skip_statement_cache? |
| 193 | +module ActiveRecord |
| 194 | + module Associations |
| 195 | + class Association |
| 196 | + alias skip_statement_cache_orig skip_statement_cache? |
193 | 197 |
|
194 |
| - def skip_statement_cache?(*scope) |
195 |
| - return true if klass.respond_to?(:scoped_by_tenant?) && klass.scoped_by_tenant? |
| 198 | + def skip_statement_cache?(*scope) |
| 199 | + return true if klass.respond_to?(:scoped_by_tenant?) && klass.scoped_by_tenant? |
196 | 200 |
|
197 |
| - if reflection.through_reflection |
198 |
| - through_klass = reflection.through_reflection.klass |
199 |
| - return true if through_klass.respond_to?(:scoped_by_tenant?) && through_klass.scoped_by_tenant? |
200 |
| - end |
| 201 | + if reflection.through_reflection |
| 202 | + through_klass = reflection.through_reflection.klass |
| 203 | + return true if through_klass.respond_to?(:scoped_by_tenant?) && through_klass.scoped_by_tenant? |
| 204 | + end |
201 | 205 |
|
202 |
| - skip_statement_cache_orig(*scope) |
| 206 | + skip_statement_cache_orig(*scope) |
| 207 | + end |
| 208 | + end |
203 | 209 | end
|
204 | 210 | end
|
0 commit comments