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.
- checksums.yaml +5 -5
- data/Appraisals +9 -55
- 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_5.2.5.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 +7 -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_5_1.rb +16 -0
- 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 -176
- data/Gemfile.lock +0 -47
- 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_4.2.8.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/gemfiles/rails_5.0.2.gemfile +0 -7
- data/gemfiles/rails_5.0.3.gemfile +0 -7
- data/gemfiles/rails_5.1.0.gemfile +0 -7
- data/gemfiles/rails_5.1.1.gemfile +0 -7
- 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/lib/store_base_sti_class_for_4_2.rb +0 -360
- data/storebasestiname_unittest.sql +0 -0
@@ -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,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,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,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,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
|