store_base_sti_class 1.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Appraisals +9 -50
- data/Gemfile.lock +25 -27
- data/LICENSE.txt +1 -1
- data/README.md +37 -10
- data/gemfiles/rails_5.0.7.gemfile +8 -0
- data/gemfiles/rails_5.1.7.gemfile +8 -0
- data/gemfiles/rails_5.2.3.gemfile +8 -0
- data/gemfiles/rails_5.2.4.gemfile +8 -0
- data/gemfiles/rails_6.0.3.gemfile +8 -0
- data/gemfiles/rails_6.1.0.gemfile +8 -0
- data/lib/store_base_sti_class.rb +9 -7
- data/lib/store_base_sti_class/version.rb +1 -1
- data/lib/store_base_sti_class_for_5_0.rb +16 -0
- data/lib/{store_base_sti_class_for_4_2.rb → store_base_sti_class_for_5_1.rb} +97 -90
- data/lib/store_base_sti_class_for_5_2.rb +176 -0
- data/lib/store_base_sti_class_for_6_0.rb +153 -0
- data/lib/store_base_sti_class_for_6_1.rb +156 -0
- data/store_base_sti_class.gemspec +1 -2
- metadata +17 -170
- data/debug.log +0 -53835
- data/gemfiles/rails_3.0.10.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.11.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.12.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.13.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.14.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.15.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.16.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.17.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.18.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.19.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.20.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.5.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.6.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.7.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.8.gemfile.lock +0 -45
- data/gemfiles/rails_3.0.9.gemfile.lock +0 -45
- data/gemfiles/rails_3.1.0.gemfile.lock +0 -49
- data/gemfiles/rails_3.1.10.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.11.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.12.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.2.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.3.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.4.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.5.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.6.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.7.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.8.gemfile.lock +0 -47
- data/gemfiles/rails_3.1.9.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.0.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.1.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.10.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.11.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.12.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.13.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.14.gemfile.lock +0 -44
- data/gemfiles/rails_3.2.15.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.16.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.17.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.18.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.19.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.2.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.20.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.21.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.22.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.3.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.4.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.5.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.6.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.7.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.8.gemfile.lock +0 -47
- data/gemfiles/rails_3.2.9.gemfile.lock +0 -47
- data/gemfiles/rails_4.0.0.gemfile +0 -7
- data/gemfiles/rails_4.0.0.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.1.gemfile +0 -7
- data/gemfiles/rails_4.0.1.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.10.gemfile +0 -7
- data/gemfiles/rails_4.0.10.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.11.1.gemfile +0 -7
- data/gemfiles/rails_4.0.11.1.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.11.gemfile +0 -7
- data/gemfiles/rails_4.0.11.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.12.gemfile +0 -7
- data/gemfiles/rails_4.0.12.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.13.gemfile +0 -7
- data/gemfiles/rails_4.0.13.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.2.gemfile +0 -7
- data/gemfiles/rails_4.0.2.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.3.gemfile +0 -7
- data/gemfiles/rails_4.0.3.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.5.gemfile +0 -7
- data/gemfiles/rails_4.0.5.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.6.gemfile +0 -7
- data/gemfiles/rails_4.0.6.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.7.gemfile +0 -7
- data/gemfiles/rails_4.0.7.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.8.gemfile +0 -7
- data/gemfiles/rails_4.0.8.gemfile.lock +0 -49
- data/gemfiles/rails_4.0.9.gemfile +0 -7
- data/gemfiles/rails_4.0.9.gemfile.lock +0 -49
- data/gemfiles/rails_4.1.0.gemfile +0 -7
- data/gemfiles/rails_4.1.0.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.1.gemfile +0 -7
- data/gemfiles/rails_4.1.1.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.10.gemfile +0 -7
- data/gemfiles/rails_4.1.10.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.11.gemfile +0 -7
- data/gemfiles/rails_4.1.11.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.12.gemfile +0 -7
- data/gemfiles/rails_4.1.12.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.13.gemfile +0 -7
- data/gemfiles/rails_4.1.13.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.14.1.gemfile +0 -7
- data/gemfiles/rails_4.1.14.1.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.14.2.gemfile +0 -7
- data/gemfiles/rails_4.1.14.2.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.14.gemfile +0 -7
- data/gemfiles/rails_4.1.14.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.15.gemfile +0 -7
- data/gemfiles/rails_4.1.15.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.2.gemfile +0 -7
- data/gemfiles/rails_4.1.2.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.3.gemfile +0 -7
- data/gemfiles/rails_4.1.3.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.4.gemfile +0 -7
- data/gemfiles/rails_4.1.4.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.5.gemfile +0 -7
- data/gemfiles/rails_4.1.5.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.6.gemfile +0 -7
- data/gemfiles/rails_4.1.6.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.7.1.gemfile +0 -7
- data/gemfiles/rails_4.1.7.1.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.7.gemfile +0 -7
- data/gemfiles/rails_4.1.7.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.8.gemfile +0 -7
- data/gemfiles/rails_4.1.8.gemfile.lock +0 -48
- data/gemfiles/rails_4.1.9.gemfile +0 -7
- data/gemfiles/rails_4.1.9.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.0.gemfile +0 -7
- data/gemfiles/rails_4.2.0.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.1.gemfile +0 -7
- data/gemfiles/rails_4.2.1.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.2.gemfile +0 -7
- data/gemfiles/rails_4.2.2.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.3.gemfile +0 -7
- data/gemfiles/rails_4.2.3.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.4.gemfile +0 -7
- data/gemfiles/rails_4.2.4.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.5.1.gemfile +0 -7
- data/gemfiles/rails_4.2.5.1.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.5.2.gemfile +0 -7
- data/gemfiles/rails_4.2.5.2.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.5.gemfile +0 -7
- data/gemfiles/rails_4.2.5.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.6.gemfile +0 -7
- data/gemfiles/rails_4.2.6.gemfile.lock +0 -48
- data/gemfiles/rails_4.2.7.1.gemfile +0 -7
- data/gemfiles/rails_4.2.7.gemfile +0 -7
- data/gemfiles/rails_5.0.0.1.gemfile +0 -7
- data/gemfiles/rails_5.0.0.gemfile +0 -7
- data/gemfiles/rails_5.0.1.gemfile +0 -7
- data/gemfiles/rails_5.0.1.gemfile.lock +0 -48
- data/lib/store_base_sti_class_for_4_0.rb +0 -337
- data/lib/store_base_sti_class_for_4_1.rb +0 -360
- data/storebasestiname_unittest.sql +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 59deb36c4e242478eb3aea835560dd54845a59120e798e7c3d2945609da51fc7
|
|
4
|
+
data.tar.gz: c2320ddcb07a37711a13dfe9d700da253c419f85a9aebec37a7c33c468fa0ac4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03e0e8037ed8d2642e239be605ea68e7fdd808c94e76741767c2d822b3045b814c04e24dff970188fd9a283e735eda67cd4f5334b347b9dab1f3d02fbd5fa957
|
|
7
|
+
data.tar.gz: 8314c4ff6de5199bdad4605ef5a042cdec5935f0e3102ed99637dd7e5d90c4616d8571eec34e64da758207e14834eb98ef05a3aa99503e8efbac3f408dc2af6c
|
data/Appraisals
CHANGED
|
@@ -1,56 +1,15 @@
|
|
|
1
|
-
RAILS_VERSIONS = %w
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
4.0.7
|
|
10
|
-
4.0.8
|
|
11
|
-
4.0.9
|
|
12
|
-
4.0.10
|
|
13
|
-
4.0.11
|
|
14
|
-
4.0.11.1
|
|
15
|
-
4.0.12
|
|
16
|
-
4.0.13
|
|
17
|
-
4.1.0
|
|
18
|
-
4.1.1
|
|
19
|
-
4.1.2
|
|
20
|
-
4.1.3
|
|
21
|
-
4.1.4
|
|
22
|
-
4.1.5
|
|
23
|
-
4.1.6
|
|
24
|
-
4.1.7
|
|
25
|
-
4.1.7.1
|
|
26
|
-
4.1.8
|
|
27
|
-
4.1.9
|
|
28
|
-
4.1.10
|
|
29
|
-
4.1.11
|
|
30
|
-
4.1.12
|
|
31
|
-
4.1.13
|
|
32
|
-
4.1.14
|
|
33
|
-
4.1.14.1
|
|
34
|
-
4.1.14.2
|
|
35
|
-
4.1.15
|
|
36
|
-
4.2.0
|
|
37
|
-
4.2.1
|
|
38
|
-
4.2.2
|
|
39
|
-
4.2.3
|
|
40
|
-
4.2.4
|
|
41
|
-
4.2.5
|
|
42
|
-
4.2.5.1
|
|
43
|
-
4.2.5.2
|
|
44
|
-
4.2.6
|
|
45
|
-
4.2.7
|
|
46
|
-
4.2.7.1
|
|
47
|
-
5.0.0
|
|
48
|
-
5.0.0.1
|
|
49
|
-
5.0.1
|
|
50
|
-
)
|
|
1
|
+
RAILS_VERSIONS = %w[
|
|
2
|
+
5.0.7
|
|
3
|
+
5.1.7
|
|
4
|
+
5.2.3
|
|
5
|
+
5.2.4
|
|
6
|
+
6.0.3
|
|
7
|
+
6.1.0
|
|
8
|
+
].freeze
|
|
51
9
|
|
|
52
10
|
RAILS_VERSIONS.each do |version|
|
|
53
11
|
appraise "rails_#{version}" do
|
|
54
12
|
gem 'activerecord', version
|
|
13
|
+
gem 'sqlite3', ['6.0.3', '6.1.0'].include?(version) ? '~> 1.4.0' : '~> 1.3.0'
|
|
55
14
|
end
|
|
56
15
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
store_base_sti_class (
|
|
4
|
+
store_base_sti_class (2.0.2)
|
|
5
5
|
activerecord (>= 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activemodel (
|
|
11
|
-
activesupport (=
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
tzinfo (~> 1.1)
|
|
23
|
-
appraisal (2.1.0)
|
|
10
|
+
activemodel (6.1.0)
|
|
11
|
+
activesupport (= 6.1.0)
|
|
12
|
+
activerecord (6.1.0)
|
|
13
|
+
activemodel (= 6.1.0)
|
|
14
|
+
activesupport (= 6.1.0)
|
|
15
|
+
activesupport (6.1.0)
|
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
|
+
i18n (>= 1.6, < 2)
|
|
18
|
+
minitest (>= 5.1)
|
|
19
|
+
tzinfo (~> 2.0)
|
|
20
|
+
zeitwerk (~> 2.3)
|
|
21
|
+
appraisal (2.3.0)
|
|
24
22
|
bundler
|
|
25
23
|
rake
|
|
26
24
|
thor (>= 0.14.0)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
tzinfo (1.2.2)
|
|
37
|
-
thread_safe (~> 0.1)
|
|
25
|
+
concurrent-ruby (1.1.7)
|
|
26
|
+
i18n (1.8.5)
|
|
27
|
+
concurrent-ruby (~> 1.0)
|
|
28
|
+
minitest (5.14.2)
|
|
29
|
+
rake (13.0.1)
|
|
30
|
+
thor (1.0.1)
|
|
31
|
+
tzinfo (2.0.3)
|
|
32
|
+
concurrent-ruby (~> 1.0)
|
|
33
|
+
zeitwerk (2.4.2)
|
|
38
34
|
|
|
39
35
|
PLATFORMS
|
|
40
36
|
ruby
|
|
@@ -43,5 +39,7 @@ DEPENDENCIES
|
|
|
43
39
|
appraisal
|
|
44
40
|
bundler
|
|
45
41
|
minitest (>= 4.0)
|
|
46
|
-
sqlite3
|
|
47
42
|
store_base_sti_class!
|
|
43
|
+
|
|
44
|
+
BUNDLED WITH
|
|
45
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
[](https://github.com/appfolio/store_base_sti_class/actions)
|
|
2
|
+
|
|
2
3
|
## Description
|
|
3
4
|
|
|
4
5
|
Given the following class definitions:
|
|
@@ -35,12 +36,18 @@ will output:
|
|
|
35
36
|
|
|
36
37
|
Notice that addressable_type column is Person even though the actual class is Vendor.
|
|
37
38
|
|
|
38
|
-
Normally, this isn't a problem, however, it can have negative performance
|
|
39
|
-
|
|
39
|
+
Normally, this isn't a problem, however, it can have negative performance
|
|
40
|
+
characteristics in certain circumstances. The most obvious one is that a join
|
|
41
|
+
with persons or an extra query is required to find out the actual type of
|
|
42
|
+
addressable.
|
|
40
43
|
|
|
41
|
-
This gem adds the ActiveRecord::Base.store_base_sti_class configuration
|
|
44
|
+
This gem adds the ActiveRecord::Base.store_base_sti_class configuration
|
|
45
|
+
option. It defaults to true for backwards compatibility. Setting it to false
|
|
46
|
+
will alter ActiveRecord's behavior to store the actual class in polymorphic
|
|
47
|
+
_type columns when STI is used.
|
|
42
48
|
|
|
43
49
|
In the example above, if the ActiveRecord::Base.store_base_sti_class is false, the output will be,
|
|
50
|
+
|
|
44
51
|
```
|
|
45
52
|
#<Vendor id: 1, type: "Vendor" ...>
|
|
46
53
|
#<Address id: 1, addressable_id: 1, addressable_type: 'Vendor' ...>
|
|
@@ -54,21 +61,41 @@ Add the following line to your Gemfile,
|
|
|
54
61
|
gem 'store_base_sti_class'
|
|
55
62
|
```
|
|
56
63
|
|
|
57
|
-
then bundle install. Once you have the gem installed, add the following to one
|
|
64
|
+
then bundle install. Once you have the gem installed, add the following to one
|
|
65
|
+
of the initializers (or make a new one) in config/initializers,
|
|
58
66
|
|
|
59
|
-
|
|
67
|
+
ActiveRecord::Base.store_base_sti_class = false
|
|
60
68
|
|
|
61
|
-
When changing this behavior, you will have write a migration to update all of
|
|
69
|
+
When changing this behavior, you will have write a migration to update all of
|
|
70
|
+
your existing _type columns accordingly. You may also need to change your
|
|
71
|
+
application if it explicitly relies on the _type columns.
|
|
62
72
|
|
|
63
73
|
## Notes
|
|
64
74
|
|
|
65
75
|
This gem incorporates work from:
|
|
76
|
+
|
|
66
77
|
- https://github.com/codepodu/store_base_sti_class_for_4_0
|
|
67
78
|
|
|
68
|
-
It currently works with ActiveRecord 4.
|
|
79
|
+
It currently works with ActiveRecord 4.2.x through 6.0.x. If you need support
|
|
80
|
+
for ActiveRecord 3.x, use a pre-1.0 version of the gem, or ActiveRecord < 4.2
|
|
81
|
+
use a pre-2.0 version of the gem.
|
|
82
|
+
|
|
83
|
+
## Conflicts
|
|
84
|
+
|
|
85
|
+
This gem produces known conflicts with these other gems:
|
|
86
|
+
|
|
87
|
+
### friendly_id
|
|
88
|
+
|
|
89
|
+
When using [friendly_id](https://github.com/norman/friendly_id) >= 5.2.5 with the [History module](https://norman.github.io/friendly_id/FriendlyId/History.html) enabled, duplicate slugs will be generated for STI subclasses with the same sluggable identifier (ex: name). This will either cause saves to fail if you have the proper indexes in place, or will cause slug lookups to be non-deterministic, either of which is undesirable.
|
|
90
|
+
|
|
91
|
+
## History
|
|
92
|
+
|
|
93
|
+
* https://github.com/rails/rails/issues/724
|
|
94
|
+
* https://github.com/rails/rails/issues/5441#issuecomment-4563865
|
|
95
|
+
* https://github.com/rails/rails/issues/4729#issuecomment-5729297
|
|
96
|
+
* https://github.com/rails/rails/issues/5441#issuecomment-264871920
|
|
69
97
|
|
|
70
98
|
## Copyright
|
|
71
99
|
|
|
72
|
-
Copyright (c) 2011-
|
|
100
|
+
Copyright (c) 2011-2019 AppFolio, inc. See LICENSE.txt for
|
|
73
101
|
further details.
|
|
74
|
-
|
data/lib/store_base_sti_class.rb
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
require 'active_record'
|
|
2
2
|
|
|
3
|
-
if ActiveRecord::VERSION::STRING =~ /^
|
|
4
|
-
require 'store_base_sti_class_for_4_0'
|
|
5
|
-
elsif ActiveRecord::VERSION::STRING =~ /^4\.1/
|
|
6
|
-
require 'store_base_sti_class_for_4_1'
|
|
7
|
-
elsif ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
8
|
-
require 'store_base_sti_class_for_4_2'
|
|
9
|
-
elsif ActiveRecord::VERSION::STRING =~ /^5\.0/
|
|
3
|
+
if ActiveRecord::VERSION::STRING =~ /^5\.0/
|
|
10
4
|
require 'store_base_sti_class_for_5_0'
|
|
5
|
+
elsif ActiveRecord::VERSION::STRING =~ /^5\.1/
|
|
6
|
+
require 'store_base_sti_class_for_5_1'
|
|
7
|
+
elsif ActiveRecord::VERSION::STRING =~ /^5\.2/
|
|
8
|
+
require 'store_base_sti_class_for_5_2'
|
|
9
|
+
elsif ActiveRecord::VERSION::STRING =~ /^6\.0/
|
|
10
|
+
require 'store_base_sti_class_for_6_0'
|
|
11
|
+
elsif ActiveRecord::VERSION::STRING =~ /^6\.1/
|
|
12
|
+
require 'store_base_sti_class_for_6_1'
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
module StoreBaseSTIClass
|
|
@@ -8,6 +8,22 @@ if ActiveRecord::VERSION::STRING =~ /^5\.0/
|
|
|
8
8
|
self.store_base_sti_class = true
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
class PredicateBuilder
|
|
12
|
+
class AssociationQueryHandler
|
|
13
|
+
def call(attribute, value)
|
|
14
|
+
queries = {}
|
|
15
|
+
|
|
16
|
+
table = value.associated_table
|
|
17
|
+
if value.base_class
|
|
18
|
+
queries[table.association_foreign_type.to_s] = ActiveRecord::Base.store_base_sti_class ? value.base_class.name : value.value.class.name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
queries[table.association_foreign_key.to_s] = value.ids
|
|
22
|
+
predicate_builder.build_from_hash(queries)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
11
27
|
module Associations
|
|
12
28
|
class Association
|
|
13
29
|
private
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'active_record/associations/join_dependency/join_part'
|
|
2
2
|
|
|
3
|
-
if ActiveRecord::VERSION::STRING =~ /^
|
|
3
|
+
if ActiveRecord::VERSION::STRING =~ /^5\.1/
|
|
4
4
|
module ActiveRecord
|
|
5
5
|
|
|
6
6
|
class Base
|
|
@@ -8,8 +8,25 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
8
8
|
self.store_base_sti_class = true
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
class PredicateBuilder
|
|
12
|
+
class AssociationQueryHandler
|
|
13
|
+
def call(attribute, value)
|
|
14
|
+
queries = {}
|
|
15
|
+
|
|
16
|
+
table = value.associated_table
|
|
17
|
+
if value.base_class
|
|
18
|
+
queries[table.association_foreign_type.to_s] = ActiveRecord::Base.store_base_sti_class ? value.base_class.name : value.value.class.name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
queries[table.association_foreign_key.to_s] = value.ids
|
|
22
|
+
predicate_builder.build_from_hash(queries)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
11
27
|
module Associations
|
|
12
28
|
class Association
|
|
29
|
+
private
|
|
13
30
|
|
|
14
31
|
def creation_attributes
|
|
15
32
|
attributes = {}
|
|
@@ -33,43 +50,35 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
33
50
|
|
|
34
51
|
class JoinDependency # :nodoc:
|
|
35
52
|
class JoinAssociation < JoinPart # :nodoc:
|
|
36
|
-
def join_constraints(foreign_table, foreign_klass,
|
|
53
|
+
def join_constraints(foreign_table, foreign_klass, join_type, tables, chain)
|
|
37
54
|
joins = []
|
|
38
|
-
|
|
55
|
+
binds = []
|
|
39
56
|
tables = tables.reverse
|
|
40
57
|
|
|
41
|
-
scope_chain_index = 0
|
|
42
|
-
scope_chain = scope_chain.reverse
|
|
43
|
-
|
|
44
58
|
# The chain starts with the target table, but we want to end with it here (makes
|
|
45
59
|
# more sense in this context), so we reverse
|
|
46
60
|
chain.reverse_each do |reflection|
|
|
47
61
|
table = tables.shift
|
|
48
62
|
klass = reflection.klass
|
|
49
63
|
|
|
50
|
-
join_keys = reflection.join_keys
|
|
64
|
+
join_keys = reflection.join_keys
|
|
51
65
|
key = join_keys.key
|
|
52
66
|
foreign_key = join_keys.foreign_key
|
|
53
67
|
|
|
54
68
|
constraint = build_constraint(klass, table, key, foreign_table, foreign_key)
|
|
55
69
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
else
|
|
60
|
-
ActiveRecord::Relation.create(klass, table).instance_exec(node, &item)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
scope_chain_index += 1
|
|
70
|
+
predicate_builder = PredicateBuilder.new(TableMetadata.new(klass, table))
|
|
71
|
+
scope_chain_items = reflection.join_scopes(table, predicate_builder)
|
|
72
|
+
klass_scope = reflection.klass_join_scope(table, predicate_builder)
|
|
64
73
|
|
|
65
|
-
scope_chain_items.concat [
|
|
74
|
+
scope_chain_items.concat [klass_scope].compact
|
|
66
75
|
|
|
67
76
|
rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
|
|
68
77
|
left.merge right
|
|
69
78
|
end
|
|
70
79
|
|
|
71
80
|
if rel && !rel.arel.constraints.empty?
|
|
72
|
-
|
|
81
|
+
binds += rel.bound_attributes
|
|
73
82
|
constraint = constraint.and rel.arel.constraints
|
|
74
83
|
end
|
|
75
84
|
|
|
@@ -81,9 +90,8 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
81
90
|
# END PATCH
|
|
82
91
|
column = klass.columns_hash[reflection.type.to_s]
|
|
83
92
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
constraint = constraint.and table[reflection.type].eq substitute
|
|
93
|
+
binds << Relation::QueryAttribute.new(column.name, value, klass.type_for_attribute(column.name))
|
|
94
|
+
constraint = constraint.and klass.arel_attribute(reflection.type, table).eq(Arel::Nodes::BindParam.new)
|
|
87
95
|
end
|
|
88
96
|
|
|
89
97
|
joins << table.create_join(table, table.create_on(constraint), join_type)
|
|
@@ -92,7 +100,7 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
92
100
|
foreign_table, foreign_klass = table, klass
|
|
93
101
|
end
|
|
94
102
|
|
|
95
|
-
JoinInformation.new joins,
|
|
103
|
+
JoinInformation.new joins, binds
|
|
96
104
|
end
|
|
97
105
|
end
|
|
98
106
|
end
|
|
@@ -115,23 +123,34 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
115
123
|
|
|
116
124
|
class Preloader
|
|
117
125
|
class Association
|
|
126
|
+
private
|
|
118
127
|
|
|
119
128
|
def build_scope
|
|
120
129
|
scope = klass.unscoped
|
|
121
130
|
|
|
122
|
-
values
|
|
123
|
-
reflection_binds = reflection_scope.bind_values
|
|
131
|
+
values = reflection_scope.values
|
|
124
132
|
preload_values = preload_scope.values
|
|
125
|
-
preload_binds = preload_scope.bind_values
|
|
126
133
|
|
|
127
|
-
scope.
|
|
134
|
+
scope.where_clause = reflection_scope.where_clause + preload_scope.where_clause
|
|
128
135
|
scope.references_values = Array(values[:references]) + Array(preload_values[:references])
|
|
129
|
-
scope.bind_values = (reflection_binds + preload_binds)
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
if preload_values[:select] || values[:select]
|
|
138
|
+
scope._select!(preload_values[:select] || values[:select])
|
|
139
|
+
end
|
|
132
140
|
scope.includes! preload_values[:includes] || values[:includes]
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
if preload_scope.joins_values.any?
|
|
142
|
+
scope.joins!(preload_scope.joins_values)
|
|
143
|
+
else
|
|
144
|
+
scope.joins!(reflection_scope.joins_values)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
if order_values = preload_values[:order] || values[:order]
|
|
148
|
+
scope.order!(order_values)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
if preload_values[:reordering] || values[:reordering]
|
|
152
|
+
scope.reordering_value = true
|
|
153
|
+
end
|
|
135
154
|
|
|
136
155
|
if preload_values[:readonly] || values[:readonly]
|
|
137
156
|
scope.readonly!
|
|
@@ -147,7 +166,7 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
147
166
|
# END PATCH
|
|
148
167
|
end
|
|
149
168
|
|
|
150
|
-
scope.unscope_values = Array(values[:unscope])
|
|
169
|
+
scope.unscope_values = Array(values[:unscope]) + Array(preload_values[:unscope])
|
|
151
170
|
klass.default_scoped.merge(scope)
|
|
152
171
|
end
|
|
153
172
|
end
|
|
@@ -162,24 +181,26 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
162
181
|
# BEGIN PATCH
|
|
163
182
|
# original: scope.where! reflection.foreign_type => options[:source_type]
|
|
164
183
|
|
|
165
|
-
adjusted_foreign_type =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
184
|
+
adjusted_foreign_type =
|
|
185
|
+
if ActiveRecord::Base.store_base_sti_class
|
|
186
|
+
options[:source_type]
|
|
187
|
+
else
|
|
188
|
+
([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
|
|
189
|
+
end
|
|
170
190
|
|
|
171
191
|
scope.where! reflection.foreign_type => adjusted_foreign_type
|
|
172
192
|
|
|
173
193
|
# END PATCH
|
|
174
194
|
else
|
|
175
|
-
unless reflection_scope.
|
|
195
|
+
unless reflection_scope.where_clause.empty?
|
|
176
196
|
scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
|
|
177
|
-
scope.
|
|
178
|
-
scope.bind_values = reflection_scope.bind_values
|
|
197
|
+
scope.where_clause = reflection_scope.where_clause
|
|
179
198
|
end
|
|
180
199
|
|
|
181
200
|
scope.references! reflection_scope.values[:references]
|
|
182
|
-
scope =
|
|
201
|
+
if scope.eager_loading? && order_values = reflection_scope.values[:order]
|
|
202
|
+
scope = scope.order(order_values)
|
|
203
|
+
end
|
|
183
204
|
end
|
|
184
205
|
|
|
185
206
|
scope
|
|
@@ -188,6 +209,7 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
188
209
|
end
|
|
189
210
|
|
|
190
211
|
class AssociationScope
|
|
212
|
+
|
|
191
213
|
def self.get_bind_values(owner, chain)
|
|
192
214
|
binds = []
|
|
193
215
|
last_reflection = chain.last
|
|
@@ -211,8 +233,10 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
211
233
|
binds
|
|
212
234
|
end
|
|
213
235
|
|
|
214
|
-
|
|
215
|
-
|
|
236
|
+
private
|
|
237
|
+
|
|
238
|
+
def next_chain_scope(scope, table, reflection, foreign_table, next_reflection)
|
|
239
|
+
join_keys = reflection.join_keys
|
|
216
240
|
key = join_keys.key
|
|
217
241
|
foreign_key = join_keys.foreign_key
|
|
218
242
|
|
|
@@ -220,49 +244,46 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
220
244
|
|
|
221
245
|
if reflection.type
|
|
222
246
|
# BEGIN PATCH
|
|
223
|
-
# original:
|
|
224
|
-
# value
|
|
225
|
-
#
|
|
226
|
-
# scope = scope.where(table[reflection.type].eq(bind_val))
|
|
247
|
+
# original:
|
|
248
|
+
# value = transform_value(next_reflection.klass.base_class.name)
|
|
249
|
+
# scope = scope.where(table.name => { reflection.type => value })
|
|
227
250
|
if ActiveRecord::Base.store_base_sti_class
|
|
228
|
-
value
|
|
229
|
-
bind_val = bind scope, table.table_name, reflection.type, value, tracker
|
|
230
|
-
scope = scope.where(table[reflection.type].eq(bind_val))
|
|
251
|
+
value = transform_value(next_reflection.klass.base_class.name)
|
|
231
252
|
else
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
scope = scope.where(table[reflection.type].in(([klass] + klass.descendants).map(&:name)))
|
|
253
|
+
klass = next_reflection.klass
|
|
254
|
+
value = ([klass] + klass.descendants).map(&:name)
|
|
235
255
|
end
|
|
256
|
+
scope = scope.where(table.name => { reflection.type => value })
|
|
236
257
|
# END PATCH
|
|
237
|
-
|
|
238
258
|
end
|
|
239
259
|
|
|
240
260
|
scope = scope.joins(join(foreign_table, constraint))
|
|
241
261
|
end
|
|
242
262
|
|
|
243
|
-
def last_chain_scope(scope, table, reflection, owner
|
|
244
|
-
join_keys = reflection.join_keys
|
|
263
|
+
def last_chain_scope(scope, table, reflection, owner)
|
|
264
|
+
join_keys = reflection.join_keys
|
|
245
265
|
key = join_keys.key
|
|
246
266
|
foreign_key = join_keys.foreign_key
|
|
247
267
|
|
|
248
|
-
|
|
249
|
-
scope
|
|
268
|
+
value = transform_value(owner[foreign_key])
|
|
269
|
+
scope = scope.where(table.name => { key => value })
|
|
250
270
|
|
|
251
271
|
if reflection.type
|
|
252
272
|
# BEGIN PATCH
|
|
253
|
-
#
|
|
254
|
-
|
|
273
|
+
# polymorphic_type = transform_value(owner.class.base_class.name)
|
|
274
|
+
polymorphic_type = transform_value(ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name)
|
|
255
275
|
# END PATCH
|
|
256
|
-
|
|
257
|
-
scope = scope.where(table[reflection.type].eq(bind_val))
|
|
258
|
-
else
|
|
259
|
-
scope
|
|
276
|
+
scope = scope.where(table.name => { reflection.type => polymorphic_type })
|
|
260
277
|
end
|
|
278
|
+
|
|
279
|
+
scope
|
|
261
280
|
end
|
|
262
|
-
|
|
281
|
+
|
|
263
282
|
end
|
|
264
283
|
|
|
265
284
|
module ThroughAssociation
|
|
285
|
+
private
|
|
286
|
+
|
|
266
287
|
def construct_join_attributes(*records)
|
|
267
288
|
ensure_mutable
|
|
268
289
|
|
|
@@ -296,10 +317,10 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
296
317
|
join_attributes
|
|
297
318
|
end
|
|
298
319
|
end
|
|
299
|
-
|
|
300
320
|
end
|
|
301
321
|
|
|
302
322
|
class HasManyThroughAssociation
|
|
323
|
+
private
|
|
303
324
|
|
|
304
325
|
def build_through_record(record)
|
|
305
326
|
@through_records[record.object_id] ||= begin
|
|
@@ -323,37 +344,23 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
|
323
344
|
end
|
|
324
345
|
|
|
325
346
|
module Reflection
|
|
326
|
-
class
|
|
327
|
-
def
|
|
328
|
-
|
|
329
|
-
|
|
347
|
+
class PolymorphicReflection
|
|
348
|
+
def source_type_info
|
|
349
|
+
type = @previous_reflection.foreign_type
|
|
350
|
+
source_type = @previous_reflection.options[:source_type]
|
|
330
351
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
type = foreign_type
|
|
338
|
-
# START PATCH
|
|
339
|
-
# original: source_type = options[:source_type]
|
|
340
|
-
source_type = if ActiveRecord::Base.store_base_sti_class
|
|
341
|
-
options[:source_type]
|
|
342
|
-
else
|
|
343
|
-
([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
|
|
344
|
-
end
|
|
345
|
-
# END PATCH
|
|
346
|
-
through_scope_chain.first << lambda { |object|
|
|
347
|
-
where(type => source_type)
|
|
348
|
-
}
|
|
352
|
+
# START PATCH
|
|
353
|
+
adjusted_source_type =
|
|
354
|
+
if ActiveRecord::Base.store_base_sti_class
|
|
355
|
+
source_type
|
|
356
|
+
else
|
|
357
|
+
([source_type.constantize] + source_type.constantize.descendants).map(&:to_s)
|
|
349
358
|
end
|
|
359
|
+
# END PATCH
|
|
350
360
|
|
|
351
|
-
|
|
352
|
-
scope_chain + through_scope_chain
|
|
353
|
-
end
|
|
361
|
+
lambda { |object| where(type => adjusted_source_type) }
|
|
354
362
|
end
|
|
355
363
|
end
|
|
356
|
-
|
|
357
364
|
end
|
|
358
365
|
end
|
|
359
366
|
|