store_base_sti_class 1.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +9 -50
  3. data/Gemfile.lock +25 -27
  4. data/LICENSE.txt +1 -1
  5. data/README.md +37 -10
  6. data/gemfiles/rails_5.0.7.gemfile +8 -0
  7. data/gemfiles/rails_5.1.7.gemfile +8 -0
  8. data/gemfiles/rails_5.2.3.gemfile +8 -0
  9. data/gemfiles/rails_5.2.4.gemfile +8 -0
  10. data/gemfiles/rails_6.0.3.gemfile +8 -0
  11. data/gemfiles/rails_6.1.0.gemfile +8 -0
  12. data/lib/store_base_sti_class.rb +9 -7
  13. data/lib/store_base_sti_class/version.rb +1 -1
  14. data/lib/store_base_sti_class_for_5_0.rb +16 -0
  15. data/lib/{store_base_sti_class_for_4_2.rb → store_base_sti_class_for_5_1.rb} +97 -90
  16. data/lib/store_base_sti_class_for_5_2.rb +176 -0
  17. data/lib/store_base_sti_class_for_6_0.rb +153 -0
  18. data/lib/store_base_sti_class_for_6_1.rb +156 -0
  19. data/store_base_sti_class.gemspec +1 -2
  20. metadata +17 -170
  21. data/debug.log +0 -53835
  22. data/gemfiles/rails_3.0.10.gemfile.lock +0 -45
  23. data/gemfiles/rails_3.0.11.gemfile.lock +0 -45
  24. data/gemfiles/rails_3.0.12.gemfile.lock +0 -45
  25. data/gemfiles/rails_3.0.13.gemfile.lock +0 -45
  26. data/gemfiles/rails_3.0.14.gemfile.lock +0 -45
  27. data/gemfiles/rails_3.0.15.gemfile.lock +0 -45
  28. data/gemfiles/rails_3.0.16.gemfile.lock +0 -45
  29. data/gemfiles/rails_3.0.17.gemfile.lock +0 -45
  30. data/gemfiles/rails_3.0.18.gemfile.lock +0 -45
  31. data/gemfiles/rails_3.0.19.gemfile.lock +0 -45
  32. data/gemfiles/rails_3.0.20.gemfile.lock +0 -45
  33. data/gemfiles/rails_3.0.5.gemfile.lock +0 -45
  34. data/gemfiles/rails_3.0.6.gemfile.lock +0 -45
  35. data/gemfiles/rails_3.0.7.gemfile.lock +0 -45
  36. data/gemfiles/rails_3.0.8.gemfile.lock +0 -45
  37. data/gemfiles/rails_3.0.9.gemfile.lock +0 -45
  38. data/gemfiles/rails_3.1.0.gemfile.lock +0 -49
  39. data/gemfiles/rails_3.1.10.gemfile.lock +0 -47
  40. data/gemfiles/rails_3.1.11.gemfile.lock +0 -47
  41. data/gemfiles/rails_3.1.12.gemfile.lock +0 -47
  42. data/gemfiles/rails_3.1.2.gemfile.lock +0 -47
  43. data/gemfiles/rails_3.1.3.gemfile.lock +0 -47
  44. data/gemfiles/rails_3.1.4.gemfile.lock +0 -47
  45. data/gemfiles/rails_3.1.5.gemfile.lock +0 -47
  46. data/gemfiles/rails_3.1.6.gemfile.lock +0 -47
  47. data/gemfiles/rails_3.1.7.gemfile.lock +0 -47
  48. data/gemfiles/rails_3.1.8.gemfile.lock +0 -47
  49. data/gemfiles/rails_3.1.9.gemfile.lock +0 -47
  50. data/gemfiles/rails_3.2.0.gemfile.lock +0 -47
  51. data/gemfiles/rails_3.2.1.gemfile.lock +0 -47
  52. data/gemfiles/rails_3.2.10.gemfile.lock +0 -47
  53. data/gemfiles/rails_3.2.11.gemfile.lock +0 -47
  54. data/gemfiles/rails_3.2.12.gemfile.lock +0 -47
  55. data/gemfiles/rails_3.2.13.gemfile.lock +0 -47
  56. data/gemfiles/rails_3.2.14.gemfile.lock +0 -44
  57. data/gemfiles/rails_3.2.15.gemfile.lock +0 -47
  58. data/gemfiles/rails_3.2.16.gemfile.lock +0 -47
  59. data/gemfiles/rails_3.2.17.gemfile.lock +0 -47
  60. data/gemfiles/rails_3.2.18.gemfile.lock +0 -47
  61. data/gemfiles/rails_3.2.19.gemfile.lock +0 -47
  62. data/gemfiles/rails_3.2.2.gemfile.lock +0 -47
  63. data/gemfiles/rails_3.2.20.gemfile.lock +0 -47
  64. data/gemfiles/rails_3.2.21.gemfile.lock +0 -47
  65. data/gemfiles/rails_3.2.22.gemfile.lock +0 -47
  66. data/gemfiles/rails_3.2.3.gemfile.lock +0 -47
  67. data/gemfiles/rails_3.2.4.gemfile.lock +0 -47
  68. data/gemfiles/rails_3.2.5.gemfile.lock +0 -47
  69. data/gemfiles/rails_3.2.6.gemfile.lock +0 -47
  70. data/gemfiles/rails_3.2.7.gemfile.lock +0 -47
  71. data/gemfiles/rails_3.2.8.gemfile.lock +0 -47
  72. data/gemfiles/rails_3.2.9.gemfile.lock +0 -47
  73. data/gemfiles/rails_4.0.0.gemfile +0 -7
  74. data/gemfiles/rails_4.0.0.gemfile.lock +0 -49
  75. data/gemfiles/rails_4.0.1.gemfile +0 -7
  76. data/gemfiles/rails_4.0.1.gemfile.lock +0 -49
  77. data/gemfiles/rails_4.0.10.gemfile +0 -7
  78. data/gemfiles/rails_4.0.10.gemfile.lock +0 -49
  79. data/gemfiles/rails_4.0.11.1.gemfile +0 -7
  80. data/gemfiles/rails_4.0.11.1.gemfile.lock +0 -49
  81. data/gemfiles/rails_4.0.11.gemfile +0 -7
  82. data/gemfiles/rails_4.0.11.gemfile.lock +0 -49
  83. data/gemfiles/rails_4.0.12.gemfile +0 -7
  84. data/gemfiles/rails_4.0.12.gemfile.lock +0 -49
  85. data/gemfiles/rails_4.0.13.gemfile +0 -7
  86. data/gemfiles/rails_4.0.13.gemfile.lock +0 -49
  87. data/gemfiles/rails_4.0.2.gemfile +0 -7
  88. data/gemfiles/rails_4.0.2.gemfile.lock +0 -49
  89. data/gemfiles/rails_4.0.3.gemfile +0 -7
  90. data/gemfiles/rails_4.0.3.gemfile.lock +0 -49
  91. data/gemfiles/rails_4.0.4.gemfile +0 -7
  92. data/gemfiles/rails_4.0.4.gemfile.lock +0 -49
  93. data/gemfiles/rails_4.0.5.gemfile +0 -7
  94. data/gemfiles/rails_4.0.5.gemfile.lock +0 -49
  95. data/gemfiles/rails_4.0.6.gemfile +0 -7
  96. data/gemfiles/rails_4.0.6.gemfile.lock +0 -49
  97. data/gemfiles/rails_4.0.7.gemfile +0 -7
  98. data/gemfiles/rails_4.0.7.gemfile.lock +0 -49
  99. data/gemfiles/rails_4.0.8.gemfile +0 -7
  100. data/gemfiles/rails_4.0.8.gemfile.lock +0 -49
  101. data/gemfiles/rails_4.0.9.gemfile +0 -7
  102. data/gemfiles/rails_4.0.9.gemfile.lock +0 -49
  103. data/gemfiles/rails_4.1.0.gemfile +0 -7
  104. data/gemfiles/rails_4.1.0.gemfile.lock +0 -48
  105. data/gemfiles/rails_4.1.1.gemfile +0 -7
  106. data/gemfiles/rails_4.1.1.gemfile.lock +0 -48
  107. data/gemfiles/rails_4.1.10.gemfile +0 -7
  108. data/gemfiles/rails_4.1.10.gemfile.lock +0 -48
  109. data/gemfiles/rails_4.1.11.gemfile +0 -7
  110. data/gemfiles/rails_4.1.11.gemfile.lock +0 -48
  111. data/gemfiles/rails_4.1.12.gemfile +0 -7
  112. data/gemfiles/rails_4.1.12.gemfile.lock +0 -48
  113. data/gemfiles/rails_4.1.13.gemfile +0 -7
  114. data/gemfiles/rails_4.1.13.gemfile.lock +0 -48
  115. data/gemfiles/rails_4.1.14.1.gemfile +0 -7
  116. data/gemfiles/rails_4.1.14.1.gemfile.lock +0 -48
  117. data/gemfiles/rails_4.1.14.2.gemfile +0 -7
  118. data/gemfiles/rails_4.1.14.2.gemfile.lock +0 -48
  119. data/gemfiles/rails_4.1.14.gemfile +0 -7
  120. data/gemfiles/rails_4.1.14.gemfile.lock +0 -48
  121. data/gemfiles/rails_4.1.15.gemfile +0 -7
  122. data/gemfiles/rails_4.1.15.gemfile.lock +0 -48
  123. data/gemfiles/rails_4.1.2.gemfile +0 -7
  124. data/gemfiles/rails_4.1.2.gemfile.lock +0 -48
  125. data/gemfiles/rails_4.1.3.gemfile +0 -7
  126. data/gemfiles/rails_4.1.3.gemfile.lock +0 -48
  127. data/gemfiles/rails_4.1.4.gemfile +0 -7
  128. data/gemfiles/rails_4.1.4.gemfile.lock +0 -48
  129. data/gemfiles/rails_4.1.5.gemfile +0 -7
  130. data/gemfiles/rails_4.1.5.gemfile.lock +0 -48
  131. data/gemfiles/rails_4.1.6.gemfile +0 -7
  132. data/gemfiles/rails_4.1.6.gemfile.lock +0 -48
  133. data/gemfiles/rails_4.1.7.1.gemfile +0 -7
  134. data/gemfiles/rails_4.1.7.1.gemfile.lock +0 -48
  135. data/gemfiles/rails_4.1.7.gemfile +0 -7
  136. data/gemfiles/rails_4.1.7.gemfile.lock +0 -48
  137. data/gemfiles/rails_4.1.8.gemfile +0 -7
  138. data/gemfiles/rails_4.1.8.gemfile.lock +0 -48
  139. data/gemfiles/rails_4.1.9.gemfile +0 -7
  140. data/gemfiles/rails_4.1.9.gemfile.lock +0 -48
  141. data/gemfiles/rails_4.2.0.gemfile +0 -7
  142. data/gemfiles/rails_4.2.0.gemfile.lock +0 -48
  143. data/gemfiles/rails_4.2.1.gemfile +0 -7
  144. data/gemfiles/rails_4.2.1.gemfile.lock +0 -48
  145. data/gemfiles/rails_4.2.2.gemfile +0 -7
  146. data/gemfiles/rails_4.2.2.gemfile.lock +0 -48
  147. data/gemfiles/rails_4.2.3.gemfile +0 -7
  148. data/gemfiles/rails_4.2.3.gemfile.lock +0 -48
  149. data/gemfiles/rails_4.2.4.gemfile +0 -7
  150. data/gemfiles/rails_4.2.4.gemfile.lock +0 -48
  151. data/gemfiles/rails_4.2.5.1.gemfile +0 -7
  152. data/gemfiles/rails_4.2.5.1.gemfile.lock +0 -48
  153. data/gemfiles/rails_4.2.5.2.gemfile +0 -7
  154. data/gemfiles/rails_4.2.5.2.gemfile.lock +0 -48
  155. data/gemfiles/rails_4.2.5.gemfile +0 -7
  156. data/gemfiles/rails_4.2.5.gemfile.lock +0 -48
  157. data/gemfiles/rails_4.2.6.gemfile +0 -7
  158. data/gemfiles/rails_4.2.6.gemfile.lock +0 -48
  159. data/gemfiles/rails_4.2.7.1.gemfile +0 -7
  160. data/gemfiles/rails_4.2.7.gemfile +0 -7
  161. data/gemfiles/rails_5.0.0.1.gemfile +0 -7
  162. data/gemfiles/rails_5.0.0.gemfile +0 -7
  163. data/gemfiles/rails_5.0.1.gemfile +0 -7
  164. data/gemfiles/rails_5.0.1.gemfile.lock +0 -48
  165. data/lib/store_base_sti_class_for_4_0.rb +0 -337
  166. data/lib/store_base_sti_class_for_4_1.rb +0 -360
  167. data/storebasestiname_unittest.sql +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8a8f045c90c480e658eb8ac2a877d4bfb31fd01c
4
- data.tar.gz: 9f1e796ef7836c594fea2e9a107939771e2669dd
2
+ SHA256:
3
+ metadata.gz: 59deb36c4e242478eb3aea835560dd54845a59120e798e7c3d2945609da51fc7
4
+ data.tar.gz: c2320ddcb07a37711a13dfe9d700da253c419f85a9aebec37a7c33c468fa0ac4
5
5
  SHA512:
6
- metadata.gz: 39a2df8993be2a04d27b318dadd3d3bc23005c418828e587592f67946b2c144caebe0101606f722b196537a654d648d332e16ddc58a30504c132aec176fd7cf7
7
- data.tar.gz: a901606a746a6c093e0086a5886d101099ae4d8a5aefca9f27cc6c5eeb99cfbd093b60192fc309f0094dafff3ff53ac405c0ccdf2f2d29522b84ee41b4124d6b
6
+ metadata.gz: 03e0e8037ed8d2642e239be605ea68e7fdd808c94e76741767c2d822b3045b814c04e24dff970188fd9a283e735eda67cd4f5334b347b9dab1f3d02fbd5fa957
7
+ data.tar.gz: 8314c4ff6de5199bdad4605ef5a042cdec5935f0e3102ed99637dd7e5d90c4616d8571eec34e64da758207e14834eb98ef05a3aa99503e8efbac3f408dc2af6c
data/Appraisals CHANGED
@@ -1,56 +1,15 @@
1
- RAILS_VERSIONS = %w(
2
- 4.0.0
3
- 4.0.1
4
- 4.0.2
5
- 4.0.3
6
- 4.0.4
7
- 4.0.5
8
- 4.0.6
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
@@ -1,40 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- store_base_sti_class (1.0.0)
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 (4.2.6)
11
- activesupport (= 4.2.6)
12
- builder (~> 3.1)
13
- activerecord (4.2.6)
14
- activemodel (= 4.2.6)
15
- activesupport (= 4.2.6)
16
- arel (~> 6.0)
17
- activesupport (4.2.6)
18
- i18n (~> 0.7)
19
- json (~> 1.7, >= 1.7.7)
20
- minitest (~> 5.1)
21
- thread_safe (~> 0.3, >= 0.3.4)
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
- arel (6.0.4)
28
- builder (3.2.3)
29
- i18n (0.8.0)
30
- json (1.8.6)
31
- minitest (5.8.4)
32
- rake (11.1.2)
33
- sqlite3 (1.3.11)
34
- thor (0.19.1)
35
- thread_safe (0.3.5)
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2015 AppFolio, inc.
1
+ Copyright (c) 2011-2019 AppFolio, inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Build Status](https://travis-ci.org/appfolio/store_base_sti_class.svg?branch=master)](https://travis-ci.org/appfolio/store_base_sti_class)
1
+ [![CI](https://github.com/appfolio/store_base_sti_class/workflows/CI/badge.svg)](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 characteristics in certain circumstances. The most obvious one is that
39
- a join with persons or an extra query is required to find out the actual type of addressable.
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 option. It defaults to true for backwards compatibility. Setting it to false will alter ActiveRecord's behavior to store the actual class in polymorphic _type columns when STI is used.
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 of the initializers (or make a new one) in config/initializers,
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
- ActiveRecord::Base.store_base_sti_class = false
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 your existing _type columns accordingly. You may also need to change your application if it explicitly relies on the _type columns.
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.0.x through 5.0.x. If you need support for ActiveRecord 3.x, use a pre-1.0 version of the gem.
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-2017 AppFolio, inc. See LICENSE.txt for
100
+ Copyright (c) 2011-2019 AppFolio, inc. See LICENSE.txt for
73
101
  further details.
74
-
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5.0.7"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5.1.7"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5.2.3"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5.2.4"
6
+ gem "sqlite3", "~> 1.3.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "6.0.3"
6
+ gem "sqlite3", "~> 1.4.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "6.1.0"
6
+ gem "sqlite3", "~> 1.4.0"
7
+
8
+ gemspec path: "../"
@@ -1,13 +1,15 @@
1
1
  require 'active_record'
2
2
 
3
- if ActiveRecord::VERSION::STRING =~ /^4\.0/
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
@@ -1,3 +1,3 @@
1
1
  module StoreBaseSTIClass
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -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 =~ /^4\.2/
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, node, join_type, tables, scope_chain, chain)
53
+ def join_constraints(foreign_table, foreign_klass, join_type, tables, chain)
37
54
  joins = []
38
- bind_values = []
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(klass)
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
- scope_chain_items = scope_chain[scope_chain_index].map do |item|
57
- if item.is_a?(Relation)
58
- item
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 [klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))].compact
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
- bind_values.concat rel.bind_values
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
- substitute = klass.connection.substitute_at(column)
85
- bind_values.push [column, value]
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, bind_values
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 = reflection_scope.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.where_values = Array(values[:where]) + Array(preload_values[:where])
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
- scope._select! preload_values[:select] || values[:select] || table[Arel.star]
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
- scope.joins! preload_values[:joins] || values[:joins]
134
- scope.order! preload_values[:order] || values[:order]
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 = if ActiveRecord::Base.store_base_sti_class
166
- options[:source_type]
167
- else
168
- ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
169
- end
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.where_values.empty?
195
+ unless reflection_scope.where_clause.empty?
176
196
  scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
177
- scope.where_values = reflection_scope.values[:where]
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 = scope.order reflection_scope.values[:order] if scope.eager_loading?
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
- def next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection)
215
- join_keys = reflection.join_keys(assoc_klass)
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 = next_reflection.klass.base_class.name
225
- # bind_val = bind scope, table.table_name, reflection.type, value, tracker
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 = next_reflection.klass.base_class.name
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
- value = next_reflection.klass.name
233
- klass = next_reflection.klass
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, tracker, assoc_klass)
244
- join_keys = reflection.join_keys(assoc_klass)
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
- bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key], tracker
249
- scope = scope.where(table[key].eq(bind_val))
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
- # original: owner.class.base_class.name
254
- value = ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name
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
- bind_val = bind scope, table.table_name, reflection.type, value, tracker
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 ThroughReflection
327
- def scope_chain
328
- @scope_chain ||= begin
329
- scope_chain = source_reflection.scope_chain.map(&:dup)
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
- # Add to it the scope from this reflection (if any)
332
- scope_chain.first << scope if scope
333
-
334
- through_scope_chain = through_reflection.scope_chain.map(&:dup)
335
-
336
- if options[:source_type]
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
- # Recursively fill out the rest of the array from the through reflection
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