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
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.5.1"
6
-
7
- gemspec :path => "../"
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- store_base_sti_class (0.5.0)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.2.5.1)
11
- activesupport (= 4.2.5.1)
12
- builder (~> 3.1)
13
- activerecord (4.2.5.1)
14
- activemodel (= 4.2.5.1)
15
- activesupport (= 4.2.5.1)
16
- arel (~> 6.0)
17
- activesupport (4.2.5.1)
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)
24
- bundler
25
- rake
26
- 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.10.1)
32
- rake (12.0.0)
33
- sqlite3 (1.3.13)
34
- thor (0.19.4)
35
- thread_safe (0.3.5)
36
- tzinfo (1.2.2)
37
- thread_safe (~> 0.1)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- activerecord (= 4.2.5.1)
44
- appraisal
45
- bundler
46
- minitest (>= 4.0)
47
- sqlite3
48
- store_base_sti_class!
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.5.2"
6
-
7
- gemspec :path => "../"
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- store_base_sti_class (0.5.0)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.2.5.2)
11
- activesupport (= 4.2.5.2)
12
- builder (~> 3.1)
13
- activerecord (4.2.5.2)
14
- activemodel (= 4.2.5.2)
15
- activesupport (= 4.2.5.2)
16
- arel (~> 6.0)
17
- activesupport (4.2.5.2)
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)
24
- bundler
25
- rake
26
- 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.10.1)
32
- rake (12.0.0)
33
- sqlite3 (1.3.13)
34
- thor (0.19.4)
35
- thread_safe (0.3.5)
36
- tzinfo (1.2.2)
37
- thread_safe (~> 0.1)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- activerecord (= 4.2.5.2)
44
- appraisal
45
- bundler
46
- minitest (>= 4.0)
47
- sqlite3
48
- store_base_sti_class!
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.5"
6
-
7
- gemspec :path => "../"
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- store_base_sti_class (0.5.0)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.2.5)
11
- activesupport (= 4.2.5)
12
- builder (~> 3.1)
13
- activerecord (4.2.5)
14
- activemodel (= 4.2.5)
15
- activesupport (= 4.2.5)
16
- arel (~> 6.0)
17
- activesupport (4.2.5)
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)
24
- bundler
25
- rake
26
- 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.10.1)
32
- rake (12.0.0)
33
- sqlite3 (1.3.13)
34
- thor (0.19.4)
35
- thread_safe (0.3.5)
36
- tzinfo (1.2.2)
37
- thread_safe (~> 0.1)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- activerecord (= 4.2.5)
44
- appraisal
45
- bundler
46
- minitest (>= 4.0)
47
- sqlite3
48
- store_base_sti_class!
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.6"
6
-
7
- gemspec :path => "../"
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- store_base_sti_class (0.5.0)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
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)
24
- bundler
25
- rake
26
- 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.10.1)
32
- rake (12.0.0)
33
- sqlite3 (1.3.13)
34
- thor (0.19.4)
35
- thread_safe (0.3.5)
36
- tzinfo (1.2.2)
37
- thread_safe (~> 0.1)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- activerecord (= 4.2.6)
44
- appraisal
45
- bundler
46
- minitest (>= 4.0)
47
- sqlite3
48
- store_base_sti_class!
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.7.1"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "4.2.7"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.0.0.1"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.0.0"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.0.1"
6
-
7
- gemspec :path => "../"
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- store_base_sti_class (0.5.0)
5
- activerecord (>= 3.0.5)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (5.0.1)
11
- activesupport (= 5.0.1)
12
- activerecord (5.0.1)
13
- activemodel (= 5.0.1)
14
- activesupport (= 5.0.1)
15
- arel (~> 7.0)
16
- activesupport (5.0.1)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- appraisal (2.1.0)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- arel (7.1.4)
26
- concurrent-ruby (1.0.4)
27
- i18n (0.8.0)
28
- minitest (5.10.1)
29
- rake (12.0.0)
30
- sqlite3 (1.3.13)
31
- thor (0.19.4)
32
- thread_safe (0.3.5)
33
- tzinfo (1.2.2)
34
- thread_safe (~> 0.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- activerecord (= 5.0.1)
41
- appraisal
42
- bundler
43
- minitest (>= 4.0)
44
- sqlite3
45
- store_base_sti_class!
46
-
47
- BUNDLED WITH
48
- 1.14.3
@@ -1,337 +0,0 @@
1
- require 'active_record'
2
-
3
- if ActiveRecord::VERSION::STRING =~ /^4\.0/
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 Associations
12
- class Association
13
-
14
- def creation_attributes
15
- attributes = {}
16
-
17
- if (reflection.macro == :has_one || reflection.macro == :has_many) && !options[:through]
18
- attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key]
19
-
20
- if reflection.options[:as]
21
- # START PATCH
22
- # original:
23
- # attributes[reflection.type] = owner.class.base_class.name
24
-
25
- attributes[reflection.type] = ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name
26
-
27
- # END PATCH
28
- end
29
- end
30
-
31
- attributes
32
- end
33
-
34
- end
35
-
36
- class JoinDependency # :nodoc:
37
- class JoinAssociation < JoinPart # :nodoc:
38
-
39
- def join_to(manager)
40
- tables = @tables.dup
41
- foreign_table = parent_table
42
- foreign_klass = parent.base_klass
43
-
44
- # The chain starts with the target table, but we want to end with it here (makes
45
- # more sense in this context), so we reverse
46
- chain.reverse.each_with_index do |reflection, i|
47
- table = tables.shift
48
-
49
- case reflection.source_macro
50
- when :belongs_to
51
- key = reflection.association_primary_key
52
- foreign_key = reflection.foreign_key
53
- when :has_and_belongs_to_many
54
- # Join the join table first...
55
- manager.from(join(
56
- table,
57
- table[reflection.foreign_key].
58
- eq(foreign_table[reflection.active_record_primary_key])
59
- ))
60
-
61
- foreign_table, table = table, tables.shift
62
-
63
- key = reflection.association_primary_key
64
- foreign_key = reflection.association_foreign_key
65
- else
66
- key = reflection.foreign_key
67
- foreign_key = reflection.active_record_primary_key
68
- end
69
-
70
- constraint = build_constraint(reflection, table, key, foreign_table, foreign_key)
71
-
72
- scope_chain_items = scope_chain[i]
73
-
74
- if reflection.type
75
- # START PATCH
76
- # original:
77
- # scope_chain_items += [
78
- # ActiveRecord::Relation.new(reflection.klass, table)
79
- # .where(reflection.type => foreign_klass.base_class.name)
80
- # ]
81
-
82
- if ActiveRecord::Base.store_base_sti_class
83
- scope_chain_items += [
84
- ActiveRecord::Relation.new(reflection.klass, table)
85
- .where(reflection.type => foreign_klass.base_class.name)
86
- ]
87
- else
88
- scope_chain_items += [
89
- ActiveRecord::Relation.new(reflection.klass, table)
90
- .where(reflection.type => ([foreign_klass] + foreign_klass.descendants).map(&:name))
91
- ]
92
- end
93
-
94
- # END PATCH
95
- end
96
-
97
- scope_chain_items += [reflection.klass.send(:build_default_scope)].compact
98
-
99
- scope_chain_items.each do |item|
100
- unless item.is_a?(Relation)
101
- item = ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item)
102
- end
103
-
104
- constraint = constraint.and(item.arel.constraints) unless item.arel.constraints.empty?
105
- end
106
-
107
- manager.from(join(table, constraint))
108
-
109
- # The current table in this iteration becomes the foreign table in the next
110
- foreign_table, foreign_klass = table, reflection.klass
111
- end
112
-
113
- manager
114
- end
115
- end
116
- end
117
-
118
-
119
- class BelongsToPolymorphicAssociation < BelongsToAssociation #:nodoc:
120
-
121
- private
122
-
123
- def replace_keys(record)
124
- super
125
-
126
- # START PATCH
127
- # original: owner[reflection.foreign_type] = record && record.class.base_class.name
128
-
129
- unless ActiveRecord::Base.store_base_sti_class
130
- owner[reflection.foreign_type] = record && record.class.sti_name
131
- else
132
- owner[reflection.foreign_type] = record && record.class.base_class.name
133
- end
134
-
135
- #END PATCH
136
- end
137
- end
138
- end
139
-
140
- module Associations
141
- class Preloader
142
- class Association
143
- private
144
-
145
- def build_scope
146
- scope = klass.unscoped
147
- scope.default_scoped = true
148
-
149
- values = reflection_scope.values
150
- preload_values = preload_scope.values
151
-
152
- scope.where_values = Array(values[:where]) + Array(preload_values[:where])
153
- scope.references_values = Array(values[:references]) + Array(preload_values[:references])
154
-
155
- scope.select preload_values[:select] || values[:select] || table[Arel.star]
156
- scope.includes! preload_values[:includes] || values[:includes]
157
-
158
- if options[:as]
159
- scope.where!(klass.table_name => {
160
-
161
- #START PATCH
162
- #original: reflection.type => model.base_class.sti_name
163
-
164
- reflection.type => ActiveRecord::Base.store_base_sti_class ? model.base_class.sti_name : model.sti_name
165
-
166
- #END PATCH
167
- })
168
- end
169
-
170
- scope
171
- end
172
- end
173
-
174
- module ThroughAssociation
175
- def through_scope
176
- through_scope = through_reflection.klass.unscoped
177
-
178
- if options[:source_type]
179
- #START PATCH
180
- #original: through_scope.where! reflection.foreign_type => options[:source_type]
181
-
182
- through_scope.where! reflection.foreign_type => ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
183
-
184
- #END PATCH
185
- else
186
- unless reflection_scope.where_values.empty?
187
- through_scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
188
- through_scope.where_values = reflection_scope.values[:where]
189
- end
190
-
191
- through_scope.references! reflection_scope.values[:references]
192
- through_scope.order! reflection_scope.values[:order] if through_scope.eager_loading?
193
- end
194
-
195
- through_scope
196
- end
197
- end
198
- end
199
-
200
- class AssociationScope
201
- def add_constraints(scope)
202
- tables = construct_tables
203
-
204
- chain.each_with_index do |reflection, i|
205
- table, foreign_table = tables.shift, tables.first
206
-
207
- if reflection.source_macro == :has_and_belongs_to_many
208
- join_table = tables.shift
209
-
210
- scope = scope.joins(join(
211
- join_table,
212
- table[reflection.association_primary_key].
213
- eq(join_table[reflection.association_foreign_key])
214
- ))
215
-
216
- table, foreign_table = join_table, tables.first
217
- end
218
-
219
- if reflection.source_macro == :belongs_to
220
- if reflection.options[:polymorphic]
221
- key = reflection.association_primary_key(self.klass)
222
- else
223
- key = reflection.association_primary_key
224
- end
225
-
226
- foreign_key = reflection.foreign_key
227
- else
228
- key = reflection.foreign_key
229
- foreign_key = reflection.active_record_primary_key
230
- end
231
-
232
- if reflection == chain.last
233
- bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key]
234
- scope = scope.where(table[key].eq(bind_val))
235
-
236
- if reflection.type
237
- # START PATCH
238
- # original: value = owner.class.base_class.name
239
-
240
- unless ActiveRecord::Base.store_base_sti_class
241
- value = owner.class.name
242
- else
243
- value = owner.class.base_class.name
244
- end
245
-
246
- # END PATCH
247
- bind_val = bind scope, table.table_name, reflection.type.to_s, value
248
- scope = scope.where(table[reflection.type].eq(bind_val))
249
- end
250
- else
251
- constraint = table[key].eq(foreign_table[foreign_key])
252
-
253
- if reflection.type
254
- # START PATCH
255
- # original: type = chain[i + 1].klass.base_class.name
256
- # constraint = constraint.and(table[reflection.type].eq(type))
257
-
258
- if ActiveRecord::Base.store_base_sti_class
259
- type = chain[i + 1].klass.base_class.name
260
- constraint = constraint.and(table[reflection.type].eq(type))
261
- else
262
- klass = chain[i + 1].klass
263
- constraint = constraint.and(table[reflection.type].in(([klass] + klass.descendants).map(&:name)))
264
- end
265
-
266
- # END PATCH
267
- end
268
-
269
- scope = scope.joins(join(foreign_table, constraint))
270
- end
271
-
272
- is_first_chain = i == 0
273
- klass = is_first_chain ? self.klass : reflection.klass
274
-
275
- # Exclude the scope of the association itself, because that
276
- # was already merged in the #scope method.
277
- scope_chain[i].each do |scope_chain_item|
278
- item = eval_scope(klass, scope_chain_item)
279
-
280
- if scope_chain_item == self.reflection.scope
281
- scope.merge! item.except(:where, :includes)
282
- end
283
-
284
- if is_first_chain
285
- scope.includes! item.includes_values
286
- end
287
-
288
- scope.where_values += item.where_values
289
- scope.order_values |= item.order_values
290
- end
291
- end
292
-
293
- scope
294
- end
295
-
296
- end
297
- end
298
-
299
- module Reflection
300
- class ThroughReflection < AssociationReflection
301
-
302
- def scope_chain
303
- @scope_chain ||= begin
304
- scope_chain = source_reflection.scope_chain.map(&:dup)
305
-
306
- # Add to it the scope from this reflection (if any)
307
- scope_chain.first << scope if scope
308
-
309
- through_scope_chain = through_reflection.scope_chain.map(&:dup)
310
-
311
- if options[:source_type]
312
- # START PATCH
313
- # original:
314
- # through_scope_chain.first <<
315
- # through_reflection.klass.where(foreign_type => options[:source_type])
316
-
317
- unless ActiveRecord::Base.store_base_sti_class
318
- through_scope_chain.first <<
319
- through_reflection.klass.where(foreign_type => ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s))
320
- else
321
- through_scope_chain.first <<
322
- through_reflection.klass.where(foreign_type => options[:source_type])
323
- end
324
-
325
- # END PATCH
326
- end
327
-
328
- # Recursively fill out the rest of the array from the through reflection
329
- scope_chain + through_scope_chain
330
- end
331
- end
332
- end
333
- end
334
-
335
- end
336
-
337
- end