store_base_sti_class 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Appraisals +8 -65
- data/Gemfile.lock +16 -18
- data/LICENSE.txt +1 -1
- data/README.md +20 -9
- data/gemfiles/rails_4.2.11.gemfile +8 -0
- data/gemfiles/rails_5.0.7.gemfile +8 -0
- data/gemfiles/rails_5.1.6.gemfile +8 -0
- data/gemfiles/rails_5.2.2.gemfile +8 -0
- data/gemfiles/rails_6.0.0.gemfile +8 -0
- data/lib/store_base_sti_class.rb +3 -5
- 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_6_0.rb +153 -0
- data/store_base_sti_class.gemspec +1 -2
- metadata +10 -85
- data/gemfiles/rails_4.0.0.gemfile +0 -7
- data/gemfiles/rails_4.0.1.gemfile +0 -7
- data/gemfiles/rails_4.0.10.gemfile +0 -7
- data/gemfiles/rails_4.0.11.1.gemfile +0 -7
- data/gemfiles/rails_4.0.11.gemfile +0 -7
- data/gemfiles/rails_4.0.12.gemfile +0 -7
- data/gemfiles/rails_4.0.13.gemfile +0 -7
- data/gemfiles/rails_4.0.2.gemfile +0 -7
- data/gemfiles/rails_4.0.3.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.0.5.gemfile +0 -7
- data/gemfiles/rails_4.0.6.gemfile +0 -7
- data/gemfiles/rails_4.0.7.gemfile +0 -7
- data/gemfiles/rails_4.0.8.gemfile +0 -7
- data/gemfiles/rails_4.0.9.gemfile +0 -7
- data/gemfiles/rails_4.1.0.gemfile +0 -7
- data/gemfiles/rails_4.1.1.gemfile +0 -7
- data/gemfiles/rails_4.1.10.gemfile +0 -7
- data/gemfiles/rails_4.1.11.gemfile +0 -7
- data/gemfiles/rails_4.1.12.gemfile +0 -7
- data/gemfiles/rails_4.1.13.gemfile +0 -7
- data/gemfiles/rails_4.1.14.1.gemfile +0 -7
- data/gemfiles/rails_4.1.14.2.gemfile +0 -7
- data/gemfiles/rails_4.1.14.gemfile +0 -7
- data/gemfiles/rails_4.1.15.gemfile +0 -7
- data/gemfiles/rails_4.1.2.gemfile +0 -7
- data/gemfiles/rails_4.1.3.gemfile +0 -7
- data/gemfiles/rails_4.1.4.gemfile +0 -7
- data/gemfiles/rails_4.1.5.gemfile +0 -7
- data/gemfiles/rails_4.1.6.gemfile +0 -7
- data/gemfiles/rails_4.1.7.1.gemfile +0 -7
- data/gemfiles/rails_4.1.7.gemfile +0 -7
- data/gemfiles/rails_4.1.8.gemfile +0 -7
- data/gemfiles/rails_4.1.9.gemfile +0 -7
- data/gemfiles/rails_4.2.0.gemfile +0 -7
- data/gemfiles/rails_4.2.1.gemfile +0 -7
- data/gemfiles/rails_4.2.10.gemfile +0 -7
- data/gemfiles/rails_4.2.2.gemfile +0 -7
- data/gemfiles/rails_4.2.3.gemfile +0 -7
- data/gemfiles/rails_4.2.4.gemfile +0 -7
- data/gemfiles/rails_4.2.5.1.gemfile +0 -7
- data/gemfiles/rails_4.2.5.2.gemfile +0 -7
- data/gemfiles/rails_4.2.5.gemfile +0 -7
- data/gemfiles/rails_4.2.6.gemfile +0 -7
- 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_4.2.9.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.2.gemfile +0 -7
- data/gemfiles/rails_5.0.3.gemfile +0 -7
- data/gemfiles/rails_5.0.4.gemfile +0 -7
- data/gemfiles/rails_5.0.5.gemfile +0 -7
- data/gemfiles/rails_5.0.6.gemfile +0 -7
- data/gemfiles/rails_5.1.0.gemfile +0 -7
- data/gemfiles/rails_5.1.1.gemfile +0 -7
- data/gemfiles/rails_5.1.2.gemfile +0 -7
- data/gemfiles/rails_5.1.3.gemfile +0 -7
- data/gemfiles/rails_5.1.4.gemfile +0 -7
- data/gemfiles/rails_5.1.5.gemfile +0 -7
- data/gemfiles/rails_5.2.0.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/store_base_sti_class-1.1.0.gem +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ee6cec99ea0b5aba6ca085f1119ad70837f40502af8b248d78d466e649b66a02
|
|
4
|
+
data.tar.gz: 6b2e0d8ba7829f225efa6eeb98fc74b30568f922bfe4664dbf8c1b060e4a3b6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 229854ef106a719bde09b41a71e821aa2cd69ee73877125f5fbc83a9b2fe9467e1e4b4f0d934579f7c1650ba53adbc581a4b08efe50837ef03fa42be6381e870
|
|
7
|
+
data.tar.gz: 950d8d123ba09b1d26c88ac3601b676ba61018e24697792487bb07da21686a4ce3749c378f667f2eb69948a51b87a3631ee2308e2346012be80629188b351bb5
|
data/Appraisals
CHANGED
|
@@ -1,71 +1,14 @@
|
|
|
1
|
-
RAILS_VERSIONS = %w
|
|
2
|
-
4.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
4.2.9
|
|
49
|
-
4.2.10
|
|
50
|
-
5.0.0
|
|
51
|
-
5.0.0.1
|
|
52
|
-
5.0.1
|
|
53
|
-
5.0.2
|
|
54
|
-
5.0.3
|
|
55
|
-
5.0.4
|
|
56
|
-
5.0.5
|
|
57
|
-
5.0.6
|
|
58
|
-
5.1.0
|
|
59
|
-
5.1.1
|
|
60
|
-
5.1.2
|
|
61
|
-
5.1.3
|
|
62
|
-
5.1.4
|
|
63
|
-
5.1.5
|
|
64
|
-
5.2.0
|
|
65
|
-
)
|
|
1
|
+
RAILS_VERSIONS = %w[
|
|
2
|
+
4.2.11
|
|
3
|
+
5.0.7
|
|
4
|
+
5.1.6
|
|
5
|
+
5.2.2
|
|
6
|
+
6.0.0
|
|
7
|
+
].freeze
|
|
66
8
|
|
|
67
9
|
RAILS_VERSIONS.each do |version|
|
|
68
10
|
appraise "rails_#{version}" do
|
|
69
11
|
gem 'activerecord', version
|
|
12
|
+
gem 'sqlite3', version == '6.0.0' ? '~> 1.4.0' : '~> 1.3.0'
|
|
70
13
|
end
|
|
71
14
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
store_base_sti_class (
|
|
4
|
+
store_base_sti_class (2.0.0)
|
|
5
5
|
activerecord (>= 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activemodel (
|
|
11
|
-
activesupport (=
|
|
12
|
-
activerecord (
|
|
13
|
-
activemodel (=
|
|
14
|
-
activesupport (=
|
|
15
|
-
|
|
16
|
-
activesupport (5.1.4)
|
|
10
|
+
activemodel (6.0.1)
|
|
11
|
+
activesupport (= 6.0.1)
|
|
12
|
+
activerecord (6.0.1)
|
|
13
|
+
activemodel (= 6.0.1)
|
|
14
|
+
activesupport (= 6.0.1)
|
|
15
|
+
activesupport (6.0.1)
|
|
17
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
18
|
-
i18n (
|
|
17
|
+
i18n (>= 0.7, < 2)
|
|
19
18
|
minitest (~> 5.1)
|
|
20
19
|
tzinfo (~> 1.1)
|
|
20
|
+
zeitwerk (~> 2.2)
|
|
21
21
|
appraisal (2.2.0)
|
|
22
22
|
bundler
|
|
23
23
|
rake
|
|
24
24
|
thor (>= 0.14.0)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
i18n (0.9.5)
|
|
25
|
+
concurrent-ruby (1.1.5)
|
|
26
|
+
i18n (1.7.0)
|
|
28
27
|
concurrent-ruby (~> 1.0)
|
|
29
|
-
minitest (5.
|
|
30
|
-
rake (
|
|
31
|
-
|
|
32
|
-
thor (0.20.0)
|
|
28
|
+
minitest (5.13.0)
|
|
29
|
+
rake (13.0.1)
|
|
30
|
+
thor (0.20.3)
|
|
33
31
|
thread_safe (0.3.6)
|
|
34
32
|
tzinfo (1.2.5)
|
|
35
33
|
thread_safe (~> 0.1)
|
|
34
|
+
zeitwerk (2.2.1)
|
|
36
35
|
|
|
37
36
|
PLATFORMS
|
|
38
37
|
ruby
|
|
@@ -41,8 +40,7 @@ DEPENDENCIES
|
|
|
41
40
|
appraisal
|
|
42
41
|
bundler
|
|
43
42
|
minitest (>= 4.0)
|
|
44
|
-
sqlite3
|
|
45
43
|
store_base_sti_class!
|
|
46
44
|
|
|
47
45
|
BUNDLED WITH
|
|
48
|
-
1.
|
|
46
|
+
1.17.2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -35,12 +35,18 @@ will output:
|
|
|
35
35
|
|
|
36
36
|
Notice that addressable_type column is Person even though the actual class is Vendor.
|
|
37
37
|
|
|
38
|
-
Normally, this isn't a problem, however, it can have negative performance
|
|
39
|
-
|
|
38
|
+
Normally, this isn't a problem, however, it can have negative performance
|
|
39
|
+
characteristics in certain circumstances. The most obvious one is that a join
|
|
40
|
+
with persons or an extra query is required to find out the actual type of
|
|
41
|
+
addressable.
|
|
40
42
|
|
|
41
|
-
This gem adds the ActiveRecord::Base.store_base_sti_class configuration
|
|
43
|
+
This gem adds the ActiveRecord::Base.store_base_sti_class configuration
|
|
44
|
+
option. It defaults to true for backwards compatibility. Setting it to false
|
|
45
|
+
will alter ActiveRecord's behavior to store the actual class in polymorphic
|
|
46
|
+
_type columns when STI is used.
|
|
42
47
|
|
|
43
48
|
In the example above, if the ActiveRecord::Base.store_base_sti_class is false, the output will be,
|
|
49
|
+
|
|
44
50
|
```
|
|
45
51
|
#<Vendor id: 1, type: "Vendor" ...>
|
|
46
52
|
#<Address id: 1, addressable_id: 1, addressable_type: 'Vendor' ...>
|
|
@@ -54,21 +60,26 @@ Add the following line to your Gemfile,
|
|
|
54
60
|
gem 'store_base_sti_class'
|
|
55
61
|
```
|
|
56
62
|
|
|
57
|
-
then bundle install. Once you have the gem installed, add the following to one
|
|
63
|
+
then bundle install. Once you have the gem installed, add the following to one
|
|
64
|
+
of the initializers (or make a new one) in config/initializers,
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
ActiveRecord::Base.store_base_sti_class = false
|
|
60
67
|
|
|
61
|
-
When changing this behavior, you will have write a migration to update all of
|
|
68
|
+
When changing this behavior, you will have write a migration to update all of
|
|
69
|
+
your existing _type columns accordingly. You may also need to change your
|
|
70
|
+
application if it explicitly relies on the _type columns.
|
|
62
71
|
|
|
63
72
|
## Notes
|
|
64
73
|
|
|
65
74
|
This gem incorporates work from:
|
|
75
|
+
|
|
66
76
|
- https://github.com/codepodu/store_base_sti_class_for_4_0
|
|
67
77
|
|
|
68
|
-
It currently works with ActiveRecord 4.
|
|
78
|
+
It currently works with ActiveRecord 4.2.x through 6.0.x. If you need support
|
|
79
|
+
for ActiveRecord 3.x, use a pre-1.0 version of the gem, or ActiveRecord < 4.2
|
|
80
|
+
use a pre-2.0 version of the gem.
|
|
69
81
|
|
|
70
82
|
## Copyright
|
|
71
83
|
|
|
72
|
-
Copyright (c) 2011-
|
|
84
|
+
Copyright (c) 2011-2019 AppFolio, inc. See LICENSE.txt for
|
|
73
85
|
further details.
|
|
74
|
-
|
data/lib/store_base_sti_class.rb
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
require 'active_record'
|
|
2
2
|
|
|
3
|
-
if ActiveRecord::VERSION::STRING =~ /^4\.
|
|
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/
|
|
3
|
+
if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
8
4
|
require 'store_base_sti_class_for_4_2'
|
|
9
5
|
elsif ActiveRecord::VERSION::STRING =~ /^5\.0/
|
|
10
6
|
require 'store_base_sti_class_for_5_0'
|
|
@@ -12,6 +8,8 @@ elsif ActiveRecord::VERSION::STRING =~ /^5\.1/
|
|
|
12
8
|
require 'store_base_sti_class_for_5_1'
|
|
13
9
|
elsif ActiveRecord::VERSION::STRING =~ /^5\.2/
|
|
14
10
|
require 'store_base_sti_class_for_5_2'
|
|
11
|
+
elsif ActiveRecord::VERSION::STRING =~ /^6\.0/
|
|
12
|
+
require 'store_base_sti_class_for_6_0'
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
module StoreBaseSTIClass
|
|
@@ -8,6 +8,22 @@ if ActiveRecord::VERSION::STRING =~ /^5\.0/
|
|
|
8
8
|
self.store_base_sti_class = true
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
class PredicateBuilder
|
|
12
|
+
class AssociationQueryHandler
|
|
13
|
+
def call(attribute, value)
|
|
14
|
+
queries = {}
|
|
15
|
+
|
|
16
|
+
table = value.associated_table
|
|
17
|
+
if value.base_class
|
|
18
|
+
queries[table.association_foreign_type.to_s] = ActiveRecord::Base.store_base_sti_class ? value.base_class.name : value.value.class.name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
queries[table.association_foreign_key.to_s] = value.ids
|
|
22
|
+
predicate_builder.build_from_hash(queries)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
11
27
|
module Associations
|
|
12
28
|
class Association
|
|
13
29
|
private
|
|
@@ -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,153 @@
|
|
|
1
|
+
require 'active_record/associations/join_dependency/join_part'
|
|
2
|
+
|
|
3
|
+
if ActiveRecord::VERSION::STRING =~ /^6\.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 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
|
+
def build_through_record(record)
|
|
114
|
+
@through_records[record.object_id] ||= begin
|
|
115
|
+
ensure_mutable
|
|
116
|
+
|
|
117
|
+
attributes = through_scope_attributes
|
|
118
|
+
attributes[source_reflection.name] = record
|
|
119
|
+
|
|
120
|
+
# START PATCH
|
|
121
|
+
if ActiveRecord::Base.store_base_sti_class
|
|
122
|
+
attributes[source_reflection.foreign_type] = options[:source_type] if options[:source_type]
|
|
123
|
+
end
|
|
124
|
+
# END PATCH
|
|
125
|
+
|
|
126
|
+
through_association.build(attributes)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
module Reflection
|
|
133
|
+
class PolymorphicReflection
|
|
134
|
+
def source_type_scope
|
|
135
|
+
type = @previous_reflection.foreign_type
|
|
136
|
+
source_type = @previous_reflection.options[:source_type]
|
|
137
|
+
|
|
138
|
+
# START PATCH
|
|
139
|
+
adjusted_source_type =
|
|
140
|
+
if ActiveRecord::Base.store_base_sti_class
|
|
141
|
+
source_type
|
|
142
|
+
else
|
|
143
|
+
([source_type.constantize] + source_type.constantize.descendants).map(&:to_s)
|
|
144
|
+
end
|
|
145
|
+
# END PATCH
|
|
146
|
+
|
|
147
|
+
lambda { |object| where(type => adjusted_source_type) }
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|