activerecord-multi-tenant 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -28
- data/Appraisals +6 -49
- data/Gemfile.lock +77 -61
- data/gemfiles/active_record_5.2.gemfile +2 -1
- data/gemfiles/active_record_5.2.gemfile.lock +38 -38
- data/gemfiles/active_record_6.0.gemfile +1 -1
- data/gemfiles/active_record_6.0.gemfile.lock +95 -95
- data/gemfiles/rails_5.2.gemfile +2 -1
- data/gemfiles/rails_5.2.gemfile.lock +38 -38
- data/gemfiles/rails_6.0.gemfile +1 -1
- data/gemfiles/rails_6.0.gemfile.lock +95 -95
- data/lib/activerecord-multi-tenant/controller_extensions.rb +2 -6
- data/lib/activerecord-multi-tenant/copy_from_client.rb +2 -2
- data/lib/activerecord-multi-tenant/migrations.rb +2 -2
- data/lib/activerecord-multi-tenant/model_extensions.rb +3 -9
- data/lib/activerecord-multi-tenant/multi_tenant.rb +1 -0
- data/lib/activerecord-multi-tenant/query_rewriter.rb +22 -73
- data/lib/activerecord-multi-tenant/sidekiq.rb +2 -1
- data/lib/activerecord-multi-tenant/version.rb +1 -1
- data/spec/activerecord-multi-tenant/controller_extensions_spec.rb +19 -24
- data/spec/activerecord-multi-tenant/model_extensions_spec.rb +6 -30
- data/spec/activerecord-multi-tenant/query_rewriter_spec.rb +8 -0
- data/spec/activerecord-multi-tenant/sidekiq_spec.rb +4 -4
- data/spec/schema.rb +1 -4
- data/spec/spec_helper.rb +1 -6
- metadata +6 -14
- data/gemfiles/active_record_5.1.gemfile +0 -15
- data/gemfiles/active_record_5.1.gemfile.lock +0 -180
- data/gemfiles/rails_4.2.gemfile +0 -16
- data/gemfiles/rails_4.2.gemfile.lock +0 -175
- data/gemfiles/rails_5.0.gemfile +0 -15
- data/gemfiles/rails_5.0.gemfile.lock +0 -180
- data/gemfiles/rails_5.1.gemfile +0 -15
- data/gemfiles/rails_5.1.gemfile.lock +0 -180
data/gemfiles/rails_6.0.gemfile
CHANGED
@@ -1,165 +1,165 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
activerecord-multi-tenant (1.0
|
4
|
+
activerecord-multi-tenant (1.1.0)
|
5
5
|
rails (>= 4.2)
|
6
6
|
request_store (>= 1.0.5)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (6.0.
|
12
|
-
actionpack (= 6.0.
|
11
|
+
actioncable (6.0.3.1)
|
12
|
+
actionpack (= 6.0.3.1)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
actionmailbox (6.0.
|
16
|
-
actionpack (= 6.0.
|
17
|
-
activejob (= 6.0.
|
18
|
-
activerecord (= 6.0.
|
19
|
-
activestorage (= 6.0.
|
20
|
-
activesupport (= 6.0.
|
15
|
+
actionmailbox (6.0.3.1)
|
16
|
+
actionpack (= 6.0.3.1)
|
17
|
+
activejob (= 6.0.3.1)
|
18
|
+
activerecord (= 6.0.3.1)
|
19
|
+
activestorage (= 6.0.3.1)
|
20
|
+
activesupport (= 6.0.3.1)
|
21
21
|
mail (>= 2.7.1)
|
22
|
-
actionmailer (6.0.
|
23
|
-
actionpack (= 6.0.
|
24
|
-
actionview (= 6.0.
|
25
|
-
activejob (= 6.0.
|
22
|
+
actionmailer (6.0.3.1)
|
23
|
+
actionpack (= 6.0.3.1)
|
24
|
+
actionview (= 6.0.3.1)
|
25
|
+
activejob (= 6.0.3.1)
|
26
26
|
mail (~> 2.5, >= 2.5.4)
|
27
27
|
rails-dom-testing (~> 2.0)
|
28
|
-
actionpack (6.0.
|
29
|
-
actionview (= 6.0.
|
30
|
-
activesupport (= 6.0.
|
31
|
-
rack (~> 2.0)
|
28
|
+
actionpack (6.0.3.1)
|
29
|
+
actionview (= 6.0.3.1)
|
30
|
+
activesupport (= 6.0.3.1)
|
31
|
+
rack (~> 2.0, >= 2.0.8)
|
32
32
|
rack-test (>= 0.6.3)
|
33
33
|
rails-dom-testing (~> 2.0)
|
34
34
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
-
actiontext (6.0.
|
36
|
-
actionpack (= 6.0.
|
37
|
-
activerecord (= 6.0.
|
38
|
-
activestorage (= 6.0.
|
39
|
-
activesupport (= 6.0.
|
35
|
+
actiontext (6.0.3.1)
|
36
|
+
actionpack (= 6.0.3.1)
|
37
|
+
activerecord (= 6.0.3.1)
|
38
|
+
activestorage (= 6.0.3.1)
|
39
|
+
activesupport (= 6.0.3.1)
|
40
40
|
nokogiri (>= 1.8.5)
|
41
|
-
actionview (6.0.
|
42
|
-
activesupport (= 6.0.
|
41
|
+
actionview (6.0.3.1)
|
42
|
+
activesupport (= 6.0.3.1)
|
43
43
|
builder (~> 3.1)
|
44
44
|
erubi (~> 1.4)
|
45
45
|
rails-dom-testing (~> 2.0)
|
46
46
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
-
activejob (6.0.
|
48
|
-
activesupport (= 6.0.
|
47
|
+
activejob (6.0.3.1)
|
48
|
+
activesupport (= 6.0.3.1)
|
49
49
|
globalid (>= 0.3.6)
|
50
|
-
activemodel (6.0.
|
51
|
-
activesupport (= 6.0.
|
52
|
-
activerecord (6.0.
|
53
|
-
activemodel (= 6.0.
|
54
|
-
activesupport (= 6.0.
|
55
|
-
activestorage (6.0.
|
56
|
-
actionpack (= 6.0.
|
57
|
-
activejob (= 6.0.
|
58
|
-
activerecord (= 6.0.
|
50
|
+
activemodel (6.0.3.1)
|
51
|
+
activesupport (= 6.0.3.1)
|
52
|
+
activerecord (6.0.3.1)
|
53
|
+
activemodel (= 6.0.3.1)
|
54
|
+
activesupport (= 6.0.3.1)
|
55
|
+
activestorage (6.0.3.1)
|
56
|
+
actionpack (= 6.0.3.1)
|
57
|
+
activejob (= 6.0.3.1)
|
58
|
+
activerecord (= 6.0.3.1)
|
59
59
|
marcel (~> 0.3.1)
|
60
|
-
activesupport (6.0.
|
60
|
+
activesupport (6.0.3.1)
|
61
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
62
62
|
i18n (>= 0.7, < 2)
|
63
63
|
minitest (~> 5.1)
|
64
64
|
tzinfo (~> 1.1)
|
65
|
-
zeitwerk (~> 2.
|
65
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
66
66
|
appraisal (2.2.0)
|
67
67
|
bundler
|
68
68
|
rake
|
69
69
|
thor (>= 0.14.0)
|
70
|
-
builder (3.2.
|
71
|
-
byebug (11.
|
70
|
+
builder (3.2.4)
|
71
|
+
byebug (11.1.3)
|
72
72
|
coderay (1.1.2)
|
73
|
-
concurrent-ruby (1.1.
|
73
|
+
concurrent-ruby (1.1.6)
|
74
74
|
connection_pool (2.2.2)
|
75
|
-
crass (1.0.
|
75
|
+
crass (1.0.6)
|
76
76
|
diff-lcs (1.3)
|
77
77
|
erubi (1.9.0)
|
78
78
|
globalid (0.4.2)
|
79
79
|
activesupport (>= 4.2.0)
|
80
|
-
i18n (1.
|
80
|
+
i18n (1.8.2)
|
81
81
|
concurrent-ruby (~> 1.0)
|
82
|
-
loofah (2.
|
82
|
+
loofah (2.5.0)
|
83
83
|
crass (~> 1.0.2)
|
84
84
|
nokogiri (>= 1.5.9)
|
85
85
|
mail (2.7.1)
|
86
86
|
mini_mime (>= 0.1.1)
|
87
87
|
marcel (0.3.3)
|
88
88
|
mimemagic (~> 0.3.2)
|
89
|
-
method_source (0.
|
90
|
-
mimemagic (0.3.
|
89
|
+
method_source (1.0.0)
|
90
|
+
mimemagic (0.3.5)
|
91
91
|
mini_mime (1.0.2)
|
92
92
|
mini_portile2 (2.4.0)
|
93
|
-
minitest (5.
|
93
|
+
minitest (5.14.1)
|
94
94
|
nio4r (2.5.2)
|
95
|
-
nokogiri (1.10.
|
95
|
+
nokogiri (1.10.9)
|
96
96
|
mini_portile2 (~> 2.4.0)
|
97
|
-
pg (1.
|
98
|
-
pry (0.
|
99
|
-
coderay (~> 1.1
|
100
|
-
method_source (~>
|
101
|
-
pry-byebug (3.
|
97
|
+
pg (1.2.3)
|
98
|
+
pry (0.13.1)
|
99
|
+
coderay (~> 1.1)
|
100
|
+
method_source (~> 1.0)
|
101
|
+
pry-byebug (3.9.0)
|
102
102
|
byebug (~> 11.0)
|
103
|
-
pry (~> 0.
|
104
|
-
rack (2.
|
105
|
-
rack-protection (2.0.
|
103
|
+
pry (~> 0.13.0)
|
104
|
+
rack (2.2.2)
|
105
|
+
rack-protection (2.0.8.1)
|
106
106
|
rack
|
107
107
|
rack-test (1.1.0)
|
108
108
|
rack (>= 1.0, < 3)
|
109
|
-
rails (6.0.
|
110
|
-
actioncable (= 6.0.
|
111
|
-
actionmailbox (= 6.0.
|
112
|
-
actionmailer (= 6.0.
|
113
|
-
actionpack (= 6.0.
|
114
|
-
actiontext (= 6.0.
|
115
|
-
actionview (= 6.0.
|
116
|
-
activejob (= 6.0.
|
117
|
-
activemodel (= 6.0.
|
118
|
-
activerecord (= 6.0.
|
119
|
-
activestorage (= 6.0.
|
120
|
-
activesupport (= 6.0.
|
109
|
+
rails (6.0.3.1)
|
110
|
+
actioncable (= 6.0.3.1)
|
111
|
+
actionmailbox (= 6.0.3.1)
|
112
|
+
actionmailer (= 6.0.3.1)
|
113
|
+
actionpack (= 6.0.3.1)
|
114
|
+
actiontext (= 6.0.3.1)
|
115
|
+
actionview (= 6.0.3.1)
|
116
|
+
activejob (= 6.0.3.1)
|
117
|
+
activemodel (= 6.0.3.1)
|
118
|
+
activerecord (= 6.0.3.1)
|
119
|
+
activestorage (= 6.0.3.1)
|
120
|
+
activesupport (= 6.0.3.1)
|
121
121
|
bundler (>= 1.3.0)
|
122
|
-
railties (= 6.0.
|
122
|
+
railties (= 6.0.3.1)
|
123
123
|
sprockets-rails (>= 2.0.0)
|
124
124
|
rails-dom-testing (2.0.3)
|
125
125
|
activesupport (>= 4.2.0)
|
126
126
|
nokogiri (>= 1.6)
|
127
127
|
rails-html-sanitizer (1.3.0)
|
128
128
|
loofah (~> 2.3)
|
129
|
-
railties (6.0.
|
130
|
-
actionpack (= 6.0.
|
131
|
-
activesupport (= 6.0.
|
129
|
+
railties (6.0.3.1)
|
130
|
+
actionpack (= 6.0.3.1)
|
131
|
+
activesupport (= 6.0.3.1)
|
132
132
|
method_source
|
133
133
|
rake (>= 0.8.7)
|
134
134
|
thor (>= 0.20.3, < 2.0)
|
135
|
-
rake (13.0.
|
136
|
-
redis (4.1.
|
137
|
-
request_store (1.
|
135
|
+
rake (13.0.1)
|
136
|
+
redis (4.1.4)
|
137
|
+
request_store (1.5.0)
|
138
138
|
rack (>= 1.4)
|
139
139
|
rspec (3.9.0)
|
140
140
|
rspec-core (~> 3.9.0)
|
141
141
|
rspec-expectations (~> 3.9.0)
|
142
142
|
rspec-mocks (~> 3.9.0)
|
143
|
-
rspec-core (3.9.
|
144
|
-
rspec-support (~> 3.9.
|
145
|
-
rspec-expectations (3.9.
|
143
|
+
rspec-core (3.9.2)
|
144
|
+
rspec-support (~> 3.9.3)
|
145
|
+
rspec-expectations (3.9.2)
|
146
146
|
diff-lcs (>= 1.2.0, < 2.0)
|
147
147
|
rspec-support (~> 3.9.0)
|
148
|
-
rspec-mocks (3.9.
|
148
|
+
rspec-mocks (3.9.1)
|
149
149
|
diff-lcs (>= 1.2.0, < 2.0)
|
150
150
|
rspec-support (~> 3.9.0)
|
151
|
-
rspec-rails (
|
152
|
-
actionpack (>=
|
153
|
-
activesupport (>=
|
154
|
-
railties (>=
|
155
|
-
rspec-core (~> 3.9
|
156
|
-
rspec-expectations (~> 3.9
|
157
|
-
rspec-mocks (~> 3.9
|
158
|
-
rspec-support (~> 3.9
|
159
|
-
rspec-support (3.9.
|
160
|
-
sidekiq (6.0.
|
151
|
+
rspec-rails (4.0.1)
|
152
|
+
actionpack (>= 4.2)
|
153
|
+
activesupport (>= 4.2)
|
154
|
+
railties (>= 4.2)
|
155
|
+
rspec-core (~> 3.9)
|
156
|
+
rspec-expectations (~> 3.9)
|
157
|
+
rspec-mocks (~> 3.9)
|
158
|
+
rspec-support (~> 3.9)
|
159
|
+
rspec-support (3.9.3)
|
160
|
+
sidekiq (6.0.7)
|
161
161
|
connection_pool (>= 2.2.2)
|
162
|
-
rack (
|
162
|
+
rack (~> 2.0)
|
163
163
|
rack-protection (>= 2.0.0)
|
164
164
|
redis (>= 4.1.0)
|
165
165
|
sprockets (4.0.0)
|
@@ -169,14 +169,14 @@ GEM
|
|
169
169
|
actionpack (>= 4.0)
|
170
170
|
activesupport (>= 4.0)
|
171
171
|
sprockets (>= 3.0.0)
|
172
|
-
thor (0.
|
172
|
+
thor (1.0.1)
|
173
173
|
thread_safe (0.3.6)
|
174
|
-
tzinfo (1.2.
|
174
|
+
tzinfo (1.2.7)
|
175
175
|
thread_safe (~> 0.1)
|
176
|
-
websocket-driver (0.7.
|
176
|
+
websocket-driver (0.7.2)
|
177
177
|
websocket-extensions (>= 0.1.0)
|
178
178
|
websocket-extensions (0.1.4)
|
179
|
-
zeitwerk (2.
|
179
|
+
zeitwerk (2.3.0)
|
180
180
|
|
181
181
|
PLATFORMS
|
182
182
|
ruby
|
@@ -187,7 +187,7 @@ DEPENDENCIES
|
|
187
187
|
pg
|
188
188
|
pry
|
189
189
|
pry-byebug
|
190
|
-
rails (~> 6.0.
|
190
|
+
rails (~> 6.0.3)
|
191
191
|
rake
|
192
192
|
rspec (>= 3.0)
|
193
193
|
rspec-rails
|
@@ -195,4 +195,4 @@ DEPENDENCIES
|
|
195
195
|
thor
|
196
196
|
|
197
197
|
BUNDLED WITH
|
198
|
-
1.
|
198
|
+
2.1.4
|
@@ -20,10 +20,6 @@ module MultiTenant
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
if defined?(ActionController::API)
|
28
|
-
ActionController::API.extend MultiTenant::ControllerExtensions
|
23
|
+
ActiveSupport.on_load(:action_controller) do |base|
|
24
|
+
base.extend MultiTenant::ControllerExtensions
|
29
25
|
end
|
@@ -44,10 +44,10 @@ module ActiveRecord
|
|
44
44
|
module SchemaStatements
|
45
45
|
alias :orig_create_table :create_table
|
46
46
|
def create_table(table_name, options = {}, &block)
|
47
|
-
ret = orig_create_table(table_name, options.except(:partition_key), &block)
|
47
|
+
ret = orig_create_table(table_name, **options.except(:partition_key), &block)
|
48
48
|
if options[:partition_key] && options[:partition_key].to_s != 'id'
|
49
49
|
execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{table_name}_pkey"
|
50
|
-
execute "ALTER TABLE #{table_name} ADD PRIMARY KEY(
|
50
|
+
execute "ALTER TABLE #{table_name} ADD PRIMARY KEY(\"#{options[:partition_key]}\", id)"
|
51
51
|
end
|
52
52
|
ret
|
53
53
|
end
|
@@ -24,11 +24,6 @@ module MultiTenant
|
|
24
24
|
def primary_key
|
25
25
|
return @primary_key if @primary_key
|
26
26
|
|
27
|
-
if ::ActiveRecord::VERSION::MAJOR < 5
|
28
|
-
@primary_key = super || DEFAULT_ID_FIELD
|
29
|
-
return @primary_key if connection.schema_cache.columns_hash(table_name).include? @primary_key
|
30
|
-
end
|
31
|
-
|
32
27
|
primary_object_keys = Array.wrap(connection.schema_cache.primary_keys(table_name)) - [partition_key]
|
33
28
|
|
34
29
|
if primary_object_keys.size == 1
|
@@ -54,7 +49,7 @@ module MultiTenant
|
|
54
49
|
|
55
50
|
# Create an implicit belongs_to association only if tenant class exists
|
56
51
|
if MultiTenant.tenant_klass_defined?(tenant_name)
|
57
|
-
belongs_to tenant_name, options.slice(:class_name, :inverse_of).merge(foreign_key: options[:partition_key])
|
52
|
+
belongs_to tenant_name, **options.slice(:class_name, :inverse_of).merge(foreign_key: options[:partition_key])
|
58
53
|
end
|
59
54
|
|
60
55
|
# New instances should have the tenant set
|
@@ -126,11 +121,10 @@ module MultiTenant
|
|
126
121
|
end
|
127
122
|
end
|
128
123
|
|
129
|
-
|
130
|
-
|
124
|
+
ActiveSupport.on_load(:active_record) do |base|
|
125
|
+
base.extend MultiTenant::ModelExtensionsClassMethods
|
131
126
|
end
|
132
127
|
|
133
|
-
|
134
128
|
class ActiveRecord::Associations::Association
|
135
129
|
alias skip_statement_cache_orig skip_statement_cache?
|
136
130
|
def skip_statement_cache?(*scope)
|
@@ -224,22 +224,20 @@ module MultiTenant
|
|
224
224
|
delete
|
225
225
|
end
|
226
226
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
232
|
-
end
|
233
|
-
super(arel, name, binds)
|
227
|
+
def update(arel, name = nil, binds = [])
|
228
|
+
model = MultiTenant.multi_tenant_model_for_arel(arel)
|
229
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
230
|
+
arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
234
231
|
end
|
232
|
+
super(arel, name, binds)
|
233
|
+
end
|
235
234
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
end
|
241
|
-
super(arel, name, binds)
|
235
|
+
def delete(arel, name = nil, binds = [])
|
236
|
+
model = MultiTenant.multi_tenant_model_for_arel(arel)
|
237
|
+
if model.present? && !MultiTenant.with_write_only_mode_enabled? && MultiTenant.current_tenant_id.present?
|
238
|
+
arel.where(MultiTenant::TenantEnforcementClause.new(model.arel_table[model.partition_key]))
|
242
239
|
end
|
240
|
+
super(arel, name, binds)
|
243
241
|
end
|
244
242
|
end
|
245
243
|
end
|
@@ -290,7 +288,7 @@ module ActiveRecord
|
|
290
288
|
|
291
289
|
node_list.select{ |n| n.is_a? Arel::Nodes::Join }.each do |node_join|
|
292
290
|
if (!node_join.right ||
|
293
|
-
(ActiveRecord::VERSION::MAJOR
|
291
|
+
(ActiveRecord::VERSION::MAJOR == 5 &&
|
294
292
|
!node_join.right.expr.right.is_a?(Arel::Attributes::Attribute)))
|
295
293
|
next
|
296
294
|
end
|
@@ -316,7 +314,7 @@ module ActiveRecord
|
|
316
314
|
|
317
315
|
private
|
318
316
|
def relations_from_node_join(node_join)
|
319
|
-
if ActiveRecord::VERSION::MAJOR
|
317
|
+
if ActiveRecord::VERSION::MAJOR == 5 || node_join.right.expr.is_a?(Arel::Nodes::Equality)
|
320
318
|
return node_join.right.expr.right.relation, node_join.right.expr.left.relation
|
321
319
|
end
|
322
320
|
|
@@ -327,71 +325,22 @@ module ActiveRecord
|
|
327
325
|
return nil, nil
|
328
326
|
end
|
329
327
|
|
330
|
-
|
328
|
+
if children[0].right.respond_to?('relation') && children[0].left.respond_to?('relation')
|
329
|
+
return children[0].right.relation, children[0].left.relation
|
330
|
+
end
|
331
|
+
|
332
|
+
return nil, nil
|
331
333
|
end
|
332
334
|
end
|
333
335
|
end
|
334
336
|
|
335
337
|
require 'active_record/base'
|
336
338
|
module MultiTenantFindBy
|
337
|
-
|
338
|
-
|
339
|
-
# way to prevent caching problems here when prepared statements are enabled
|
340
|
-
def find_by(*args)
|
341
|
-
return super unless respond_to?(:scoped_by_tenant?) && scoped_by_tenant?
|
342
|
-
|
343
|
-
# This duplicates a bunch of code from AR's find() method
|
344
|
-
return super if current_scope || !(Hash === args.first) || reflect_on_all_aggregations.any?
|
345
|
-
return super if default_scopes.any?
|
346
|
-
|
347
|
-
hash = args.first
|
348
|
-
|
349
|
-
return super if hash.values.any? { |v| v.nil? || Array === v || Hash === v }
|
350
|
-
return super unless hash.keys.all? { |k| columns_hash.has_key?(k.to_s) }
|
351
|
-
|
352
|
-
key = hash.keys
|
339
|
+
def cached_find_by_statement(key, &block)
|
340
|
+
return super unless respond_to?(:scoped_by_tenant?) && scoped_by_tenant?
|
353
341
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
super
|
358
|
-
end
|
359
|
-
|
360
|
-
def find(*ids)
|
361
|
-
return super unless respond_to?(:scoped_by_tenant?) && scoped_by_tenant?
|
362
|
-
|
363
|
-
# This duplicates a bunch of code from AR's find() method
|
364
|
-
return super unless ids.length == 1
|
365
|
-
return super if ids.first.kind_of?(Symbol)
|
366
|
-
return super if block_given? ||
|
367
|
-
primary_key.nil? ||
|
368
|
-
default_scopes.any? ||
|
369
|
-
current_scope ||
|
370
|
-
columns_hash.include?(inheritance_column) ||
|
371
|
-
ids.first.kind_of?(Array)
|
372
|
-
|
373
|
-
id = ids.first
|
374
|
-
if ActiveRecord::Base === id
|
375
|
-
id = id.id
|
376
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
377
|
-
You are passing an instance of ActiveRecord::Base to `find`.
|
378
|
-
Please pass the id of the object by calling `.id`
|
379
|
-
MSG
|
380
|
-
end
|
381
|
-
key = primary_key
|
382
|
-
|
383
|
-
# Ensure we never use the cached version
|
384
|
-
find_by_statement_cache.synchronize { find_by_statement_cache[key] = nil }
|
385
|
-
|
386
|
-
super
|
387
|
-
end
|
388
|
-
elsif ActiveRecord::VERSION::MAJOR > 4
|
389
|
-
def cached_find_by_statement(key, &block)
|
390
|
-
return super unless respond_to?(:scoped_by_tenant?) && scoped_by_tenant?
|
391
|
-
|
392
|
-
key = Array.wrap(key) + [MultiTenant.current_tenant_id.to_s]
|
393
|
-
super(key, &block)
|
394
|
-
end
|
342
|
+
key = Array.wrap(key) + [MultiTenant.current_tenant_id.to_s]
|
343
|
+
super(key, &block)
|
395
344
|
end
|
396
345
|
end
|
397
346
|
|