store_base_sti_class 1.1.0 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +9 -55
  3. data/LICENSE.txt +1 -1
  4. data/README.md +37 -10
  5. data/gemfiles/rails_5.0.7.gemfile +8 -0
  6. data/gemfiles/rails_5.1.7.gemfile +8 -0
  7. data/gemfiles/rails_5.2.3.gemfile +8 -0
  8. data/gemfiles/rails_5.2.4.gemfile +8 -0
  9. data/gemfiles/rails_5.2.5.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 +7 -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_5_1.rb +16 -0
  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 -176
  21. data/Gemfile.lock +0 -47
  22. data/debug.log +0 -53835
  23. data/gemfiles/rails_3.0.10.gemfile.lock +0 -45
  24. data/gemfiles/rails_3.0.11.gemfile.lock +0 -45
  25. data/gemfiles/rails_3.0.12.gemfile.lock +0 -45
  26. data/gemfiles/rails_3.0.13.gemfile.lock +0 -45
  27. data/gemfiles/rails_3.0.14.gemfile.lock +0 -45
  28. data/gemfiles/rails_3.0.15.gemfile.lock +0 -45
  29. data/gemfiles/rails_3.0.16.gemfile.lock +0 -45
  30. data/gemfiles/rails_3.0.17.gemfile.lock +0 -45
  31. data/gemfiles/rails_3.0.18.gemfile.lock +0 -45
  32. data/gemfiles/rails_3.0.19.gemfile.lock +0 -45
  33. data/gemfiles/rails_3.0.20.gemfile.lock +0 -45
  34. data/gemfiles/rails_3.0.5.gemfile.lock +0 -45
  35. data/gemfiles/rails_3.0.6.gemfile.lock +0 -45
  36. data/gemfiles/rails_3.0.7.gemfile.lock +0 -45
  37. data/gemfiles/rails_3.0.8.gemfile.lock +0 -45
  38. data/gemfiles/rails_3.0.9.gemfile.lock +0 -45
  39. data/gemfiles/rails_3.1.0.gemfile.lock +0 -49
  40. data/gemfiles/rails_3.1.10.gemfile.lock +0 -47
  41. data/gemfiles/rails_3.1.11.gemfile.lock +0 -47
  42. data/gemfiles/rails_3.1.12.gemfile.lock +0 -47
  43. data/gemfiles/rails_3.1.2.gemfile.lock +0 -47
  44. data/gemfiles/rails_3.1.3.gemfile.lock +0 -47
  45. data/gemfiles/rails_3.1.4.gemfile.lock +0 -47
  46. data/gemfiles/rails_3.1.5.gemfile.lock +0 -47
  47. data/gemfiles/rails_3.1.6.gemfile.lock +0 -47
  48. data/gemfiles/rails_3.1.7.gemfile.lock +0 -47
  49. data/gemfiles/rails_3.1.8.gemfile.lock +0 -47
  50. data/gemfiles/rails_3.1.9.gemfile.lock +0 -47
  51. data/gemfiles/rails_3.2.0.gemfile.lock +0 -47
  52. data/gemfiles/rails_3.2.1.gemfile.lock +0 -47
  53. data/gemfiles/rails_3.2.10.gemfile.lock +0 -47
  54. data/gemfiles/rails_3.2.11.gemfile.lock +0 -47
  55. data/gemfiles/rails_3.2.12.gemfile.lock +0 -47
  56. data/gemfiles/rails_3.2.13.gemfile.lock +0 -47
  57. data/gemfiles/rails_3.2.14.gemfile.lock +0 -44
  58. data/gemfiles/rails_3.2.15.gemfile.lock +0 -47
  59. data/gemfiles/rails_3.2.16.gemfile.lock +0 -47
  60. data/gemfiles/rails_3.2.17.gemfile.lock +0 -47
  61. data/gemfiles/rails_3.2.18.gemfile.lock +0 -47
  62. data/gemfiles/rails_3.2.19.gemfile.lock +0 -47
  63. data/gemfiles/rails_3.2.2.gemfile.lock +0 -47
  64. data/gemfiles/rails_3.2.20.gemfile.lock +0 -47
  65. data/gemfiles/rails_3.2.21.gemfile.lock +0 -47
  66. data/gemfiles/rails_3.2.22.gemfile.lock +0 -47
  67. data/gemfiles/rails_3.2.3.gemfile.lock +0 -47
  68. data/gemfiles/rails_3.2.4.gemfile.lock +0 -47
  69. data/gemfiles/rails_3.2.5.gemfile.lock +0 -47
  70. data/gemfiles/rails_3.2.6.gemfile.lock +0 -47
  71. data/gemfiles/rails_3.2.7.gemfile.lock +0 -47
  72. data/gemfiles/rails_3.2.8.gemfile.lock +0 -47
  73. data/gemfiles/rails_3.2.9.gemfile.lock +0 -47
  74. data/gemfiles/rails_4.0.0.gemfile +0 -7
  75. data/gemfiles/rails_4.0.0.gemfile.lock +0 -49
  76. data/gemfiles/rails_4.0.1.gemfile +0 -7
  77. data/gemfiles/rails_4.0.1.gemfile.lock +0 -49
  78. data/gemfiles/rails_4.0.10.gemfile +0 -7
  79. data/gemfiles/rails_4.0.10.gemfile.lock +0 -49
  80. data/gemfiles/rails_4.0.11.1.gemfile +0 -7
  81. data/gemfiles/rails_4.0.11.1.gemfile.lock +0 -49
  82. data/gemfiles/rails_4.0.11.gemfile +0 -7
  83. data/gemfiles/rails_4.0.11.gemfile.lock +0 -49
  84. data/gemfiles/rails_4.0.12.gemfile +0 -7
  85. data/gemfiles/rails_4.0.12.gemfile.lock +0 -49
  86. data/gemfiles/rails_4.0.13.gemfile +0 -7
  87. data/gemfiles/rails_4.0.13.gemfile.lock +0 -49
  88. data/gemfiles/rails_4.0.2.gemfile +0 -7
  89. data/gemfiles/rails_4.0.2.gemfile.lock +0 -49
  90. data/gemfiles/rails_4.0.3.gemfile +0 -7
  91. data/gemfiles/rails_4.0.3.gemfile.lock +0 -49
  92. data/gemfiles/rails_4.0.4.gemfile +0 -7
  93. data/gemfiles/rails_4.0.4.gemfile.lock +0 -49
  94. data/gemfiles/rails_4.0.5.gemfile +0 -7
  95. data/gemfiles/rails_4.0.5.gemfile.lock +0 -49
  96. data/gemfiles/rails_4.0.6.gemfile +0 -7
  97. data/gemfiles/rails_4.0.6.gemfile.lock +0 -49
  98. data/gemfiles/rails_4.0.7.gemfile +0 -7
  99. data/gemfiles/rails_4.0.7.gemfile.lock +0 -49
  100. data/gemfiles/rails_4.0.8.gemfile +0 -7
  101. data/gemfiles/rails_4.0.8.gemfile.lock +0 -49
  102. data/gemfiles/rails_4.0.9.gemfile +0 -7
  103. data/gemfiles/rails_4.0.9.gemfile.lock +0 -49
  104. data/gemfiles/rails_4.1.0.gemfile +0 -7
  105. data/gemfiles/rails_4.1.0.gemfile.lock +0 -48
  106. data/gemfiles/rails_4.1.1.gemfile +0 -7
  107. data/gemfiles/rails_4.1.1.gemfile.lock +0 -48
  108. data/gemfiles/rails_4.1.10.gemfile +0 -7
  109. data/gemfiles/rails_4.1.10.gemfile.lock +0 -48
  110. data/gemfiles/rails_4.1.11.gemfile +0 -7
  111. data/gemfiles/rails_4.1.11.gemfile.lock +0 -48
  112. data/gemfiles/rails_4.1.12.gemfile +0 -7
  113. data/gemfiles/rails_4.1.12.gemfile.lock +0 -48
  114. data/gemfiles/rails_4.1.13.gemfile +0 -7
  115. data/gemfiles/rails_4.1.13.gemfile.lock +0 -48
  116. data/gemfiles/rails_4.1.14.1.gemfile +0 -7
  117. data/gemfiles/rails_4.1.14.1.gemfile.lock +0 -48
  118. data/gemfiles/rails_4.1.14.2.gemfile +0 -7
  119. data/gemfiles/rails_4.1.14.2.gemfile.lock +0 -48
  120. data/gemfiles/rails_4.1.14.gemfile +0 -7
  121. data/gemfiles/rails_4.1.14.gemfile.lock +0 -48
  122. data/gemfiles/rails_4.1.15.gemfile +0 -7
  123. data/gemfiles/rails_4.1.15.gemfile.lock +0 -48
  124. data/gemfiles/rails_4.1.2.gemfile +0 -7
  125. data/gemfiles/rails_4.1.2.gemfile.lock +0 -48
  126. data/gemfiles/rails_4.1.3.gemfile +0 -7
  127. data/gemfiles/rails_4.1.3.gemfile.lock +0 -48
  128. data/gemfiles/rails_4.1.4.gemfile +0 -7
  129. data/gemfiles/rails_4.1.4.gemfile.lock +0 -48
  130. data/gemfiles/rails_4.1.5.gemfile +0 -7
  131. data/gemfiles/rails_4.1.5.gemfile.lock +0 -48
  132. data/gemfiles/rails_4.1.6.gemfile +0 -7
  133. data/gemfiles/rails_4.1.6.gemfile.lock +0 -48
  134. data/gemfiles/rails_4.1.7.1.gemfile +0 -7
  135. data/gemfiles/rails_4.1.7.1.gemfile.lock +0 -48
  136. data/gemfiles/rails_4.1.7.gemfile +0 -7
  137. data/gemfiles/rails_4.1.7.gemfile.lock +0 -48
  138. data/gemfiles/rails_4.1.8.gemfile +0 -7
  139. data/gemfiles/rails_4.1.8.gemfile.lock +0 -48
  140. data/gemfiles/rails_4.1.9.gemfile +0 -7
  141. data/gemfiles/rails_4.1.9.gemfile.lock +0 -48
  142. data/gemfiles/rails_4.2.0.gemfile +0 -7
  143. data/gemfiles/rails_4.2.0.gemfile.lock +0 -48
  144. data/gemfiles/rails_4.2.1.gemfile +0 -7
  145. data/gemfiles/rails_4.2.1.gemfile.lock +0 -48
  146. data/gemfiles/rails_4.2.2.gemfile +0 -7
  147. data/gemfiles/rails_4.2.2.gemfile.lock +0 -48
  148. data/gemfiles/rails_4.2.3.gemfile +0 -7
  149. data/gemfiles/rails_4.2.3.gemfile.lock +0 -48
  150. data/gemfiles/rails_4.2.4.gemfile +0 -7
  151. data/gemfiles/rails_4.2.4.gemfile.lock +0 -48
  152. data/gemfiles/rails_4.2.5.1.gemfile +0 -7
  153. data/gemfiles/rails_4.2.5.1.gemfile.lock +0 -48
  154. data/gemfiles/rails_4.2.5.2.gemfile +0 -7
  155. data/gemfiles/rails_4.2.5.2.gemfile.lock +0 -48
  156. data/gemfiles/rails_4.2.5.gemfile +0 -7
  157. data/gemfiles/rails_4.2.5.gemfile.lock +0 -48
  158. data/gemfiles/rails_4.2.6.gemfile +0 -7
  159. data/gemfiles/rails_4.2.6.gemfile.lock +0 -48
  160. data/gemfiles/rails_4.2.7.1.gemfile +0 -7
  161. data/gemfiles/rails_4.2.7.gemfile +0 -7
  162. data/gemfiles/rails_4.2.8.gemfile +0 -7
  163. data/gemfiles/rails_5.0.0.1.gemfile +0 -7
  164. data/gemfiles/rails_5.0.0.gemfile +0 -7
  165. data/gemfiles/rails_5.0.1.gemfile +0 -7
  166. data/gemfiles/rails_5.0.1.gemfile.lock +0 -48
  167. data/gemfiles/rails_5.0.2.gemfile +0 -7
  168. data/gemfiles/rails_5.0.3.gemfile +0 -7
  169. data/gemfiles/rails_5.1.0.gemfile +0 -7
  170. data/gemfiles/rails_5.1.1.gemfile +0 -7
  171. data/lib/store_base_sti_class_for_4_0.rb +0 -337
  172. data/lib/store_base_sti_class_for_4_1.rb +0 -360
  173. data/lib/store_base_sti_class_for_4_2.rb +0 -360
  174. data/storebasestiname_unittest.sql +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 82287e5bc596474535ed2f815cb34cbfe2abb089
4
- data.tar.gz: 3f1999f09ccaa5f380cb4230f4cba6eb81c2dc2e
2
+ SHA256:
3
+ metadata.gz: 5e65e14ac35f409bec5e78c411a0b3fac80ca189d8e77f693fc2ecc9f4cf609d
4
+ data.tar.gz: c0aabbee8bba07b1818f5f2fca9f94a916f56e29bcff73d9f1919fa53d269bcc
5
5
  SHA512:
6
- metadata.gz: fccef96be8809df757d5936781d2fe4811b5d4fd56d5b53fd026448c35d86288f4c10327b1562b4478e360f7e38f2c8406a7b3995b2364ffff05cfaf231b8d00
7
- data.tar.gz: 94e2b0a7c09cfcd051f791077636c9d0301687cd713ce0d899efc39994fbf07e5604e9f38a3ecd02ec008774f43694f5ed354103983e193fc1d7e0f25bade606
6
+ metadata.gz: 6078f16de9958cead9799a9da35830c2c031c17bbead961b801f6194905e65e43ab6f002ab34fd34ef6431e0b8f9ab1fc52b0c502372a3957a768480459df882
7
+ data.tar.gz: 22e514b7f2ce662d2cfa8f8fe6b2bc62f4491defe8b182c76121922f01ca7929146f546cfb7eab0d8d42ba8417c4343ae54d616cb949a44bba48c98fa5b0469f
data/Appraisals CHANGED
@@ -1,61 +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
- 4.2.8
48
- 5.0.0
49
- 5.0.0.1
50
- 5.0.1
51
- 5.0.2
52
- 5.0.3
53
- 5.1.0
54
- 5.1.1
55
- )
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
56
9
 
57
10
  RAILS_VERSIONS.each do |version|
58
11
  appraise "rails_#{version}" do
59
12
  gem 'activerecord', version
13
+ gem 'sqlite3', ['6.0.3', '6.1.0'].include?(version) ? '~> 1.4.0' : '~> 1.3.0'
60
14
  end
61
15
  end
data/LICENSE.txt CHANGED
@@ -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", "5.2.5"
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,15 +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'
11
5
  elsif ActiveRecord::VERSION::STRING =~ /^5\.1/
12
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'
13
13
  end
14
14
 
15
15
  module StoreBaseSTIClass
@@ -1,3 +1,3 @@
1
1
  module StoreBaseSTIClass
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '2.0.3'.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
@@ -8,6 +8,22 @@ if ActiveRecord::VERSION::STRING =~ /^5\.1/
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
@@ -0,0 +1,176 @@
1
+ require 'active_record/associations/join_dependency/join_part'
2
+
3
+ if ActiveRecord::VERSION::STRING =~ /^5\.2/
4
+ module ActiveRecord
5
+
6
+ class Base
7
+ class_attribute :store_base_sti_class
8
+ self.store_base_sti_class = true
9
+ end
10
+
11
+ module Inheritance
12
+ module ClassMethods
13
+ def polymorphic_name
14
+ ActiveRecord::Base.store_base_sti_class ? base_class.name : name
15
+ end
16
+ end
17
+ end
18
+
19
+ module Associations
20
+ class Preloader
21
+ class ThroughAssociation < Association
22
+ private
23
+
24
+ def through_scope
25
+ scope = through_reflection.klass.unscoped
26
+ options = reflection.options
27
+
28
+ if options[:source_type]
29
+
30
+ # BEGIN PATCH
31
+ # original:
32
+ # scope.where! reflection.foreign_type => options[:source_type]
33
+
34
+ adjusted_foreign_type =
35
+ if ActiveRecord::Base.store_base_sti_class
36
+ options[:source_type]
37
+ else
38
+ ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
39
+ end
40
+
41
+ scope.where! reflection.foreign_type => adjusted_foreign_type
42
+ # END PATCH
43
+
44
+ elsif !reflection_scope.where_clause.empty?
45
+ scope.where_clause = reflection_scope.where_clause
46
+ values = reflection_scope.values
47
+
48
+ if includes = values[:includes]
49
+ scope.includes!(source_reflection.name => includes)
50
+ else
51
+ scope.includes!(source_reflection.name)
52
+ end
53
+
54
+ if values[:references] && !values[:references].empty?
55
+ scope.references!(values[:references])
56
+ else
57
+ scope.references!(source_reflection.table_name)
58
+ end
59
+
60
+ if joins = values[:joins]
61
+ scope.joins!(source_reflection.name => joins)
62
+ end
63
+
64
+ if left_outer_joins = values[:left_outer_joins]
65
+ scope.left_outer_joins!(source_reflection.name => left_outer_joins)
66
+ end
67
+
68
+ if scope.eager_loading? && order_values = values[:order]
69
+ scope = scope.order(order_values)
70
+ end
71
+ end
72
+
73
+ scope unless scope.empty_scope?
74
+ end
75
+ end
76
+ end
77
+
78
+ class AssociationScope
79
+ private
80
+
81
+ def next_chain_scope(scope, reflection, next_reflection)
82
+ join_keys = reflection.join_keys
83
+ key = join_keys.key
84
+ foreign_key = join_keys.foreign_key
85
+
86
+ table = reflection.aliased_table
87
+ foreign_table = next_reflection.aliased_table
88
+ constraint = table[key].eq(foreign_table[foreign_key])
89
+
90
+ if reflection.type
91
+ # BEGIN PATCH
92
+ # original:
93
+ # value = transform_value(next_reflection.klass.polymorphic_name)
94
+ # scope = apply_scope(scope, table, reflection.type, value)
95
+ if ActiveRecord::Base.store_base_sti_class
96
+ value = transform_value(next_reflection.klass.polymorphic_name)
97
+ else
98
+ klass = next_reflection.klass
99
+ value = ([klass] + klass.descendants).map(&:name)
100
+ end
101
+ scope = apply_scope(scope, table, reflection.type, value)
102
+ # END PATCH
103
+ end
104
+
105
+ scope.joins!(join(foreign_table, constraint))
106
+ end
107
+
108
+ end
109
+
110
+ class HasManyThroughAssociation
111
+ private
112
+
113
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.2.4')
114
+ def build_through_record(record)
115
+ @through_records[record.object_id] ||= begin
116
+ ensure_mutable
117
+
118
+ attributes = through_scope_attributes
119
+ attributes[source_reflection.name] = record
120
+
121
+ # START PATCH
122
+ if ActiveRecord::Base.store_base_sti_class
123
+ if options[:source_type]
124
+ attributes[source_reflection.foreign_type] = options[:source_type]
125
+ end
126
+ end
127
+ # END PATCH
128
+
129
+ through_association.build(attributes)
130
+ end
131
+ end
132
+ else
133
+ def build_through_record(record)
134
+ @through_records[record.object_id] ||= begin
135
+ ensure_mutable
136
+
137
+ through_record = through_association.build(*options_for_through_record)
138
+ through_record.send("#{source_reflection.name}=", record)
139
+
140
+ # START PATCH
141
+ if ActiveRecord::Base.store_base_sti_class
142
+ if options[:source_type]
143
+ through_record.send("#{source_reflection.foreign_type}=", options[:source_type])
144
+ end
145
+ end
146
+ # END PATCH
147
+
148
+ through_record
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ module Reflection
156
+ class PolymorphicReflection
157
+ def source_type_scope
158
+ type = @previous_reflection.foreign_type
159
+ source_type = @previous_reflection.options[:source_type]
160
+
161
+ # START PATCH
162
+ adjusted_source_type =
163
+ if ActiveRecord::Base.store_base_sti_class
164
+ source_type
165
+ else
166
+ ([source_type.constantize] + source_type.constantize.descendants).map(&:to_s)
167
+ end
168
+ # END PATCH
169
+
170
+ lambda { |object| where(type => adjusted_source_type) }
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ end