store_base_sti_class 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +88 -89
- data/Gemfile.lock +15 -14
- data/{README.rdoc → README.md} +32 -22
- data/debug.log +41183 -13
- data/gemfiles/rails_3.0.10.gemfile +1 -1
- data/gemfiles/rails_3.0.10.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.11.gemfile +1 -1
- data/gemfiles/rails_3.0.11.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.12.gemfile +1 -1
- data/gemfiles/rails_3.0.12.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.13.gemfile +1 -1
- data/gemfiles/rails_3.0.13.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.14.gemfile +1 -1
- data/gemfiles/rails_3.0.14.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.15.gemfile +1 -1
- data/gemfiles/rails_3.0.15.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.16.gemfile +1 -1
- data/gemfiles/rails_3.0.16.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.17.gemfile +1 -1
- data/gemfiles/rails_3.0.17.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.18.gemfile +1 -1
- data/gemfiles/rails_3.0.18.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.19.gemfile +1 -1
- data/gemfiles/rails_3.0.19.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.20.gemfile +1 -1
- data/gemfiles/rails_3.0.20.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.5.gemfile +1 -1
- data/gemfiles/rails_3.0.5.gemfile.lock +6 -3
- data/gemfiles/rails_3.0.6.gemfile +1 -1
- data/gemfiles/rails_3.0.6.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.7.gemfile +1 -1
- data/gemfiles/rails_3.0.7.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.8.gemfile +1 -1
- data/gemfiles/rails_3.0.8.gemfile.lock +45 -0
- data/gemfiles/rails_3.0.9.gemfile +1 -1
- data/gemfiles/rails_3.0.9.gemfile.lock +45 -0
- data/gemfiles/rails_3.1.0.gemfile +1 -1
- data/gemfiles/rails_3.1.0.gemfile.lock +49 -0
- data/gemfiles/rails_3.1.10.gemfile +1 -1
- data/gemfiles/rails_3.1.10.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.11.gemfile +1 -1
- data/gemfiles/rails_3.1.11.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.12.gemfile +1 -1
- data/gemfiles/rails_3.1.12.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.2.gemfile +1 -1
- data/gemfiles/rails_3.1.2.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.3.gemfile +1 -1
- data/gemfiles/rails_3.1.3.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.4.gemfile +1 -1
- data/gemfiles/rails_3.1.4.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.5.gemfile +1 -1
- data/gemfiles/rails_3.1.5.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.6.gemfile +1 -1
- data/gemfiles/rails_3.1.6.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.7.gemfile +1 -1
- data/gemfiles/rails_3.1.7.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.8.gemfile +1 -1
- data/gemfiles/rails_3.1.8.gemfile.lock +47 -0
- data/gemfiles/rails_3.1.9.gemfile +1 -1
- data/gemfiles/rails_3.1.9.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.0.gemfile +1 -1
- data/gemfiles/rails_3.2.0.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.1.gemfile +1 -1
- data/gemfiles/rails_3.2.1.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.10.gemfile +1 -1
- data/gemfiles/rails_3.2.10.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.11.gemfile +1 -1
- data/gemfiles/rails_3.2.11.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.12.gemfile +1 -1
- data/gemfiles/rails_3.2.12.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.13.gemfile +1 -1
- data/gemfiles/rails_3.2.13.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.14.gemfile +1 -1
- data/gemfiles/rails_3.2.14.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.15.gemfile +1 -1
- data/gemfiles/rails_3.2.15.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.16.gemfile +1 -1
- data/gemfiles/rails_3.2.16.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.17.gemfile +1 -1
- data/gemfiles/rails_3.2.17.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.18.gemfile +1 -1
- data/gemfiles/rails_3.2.18.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.19.gemfile +1 -1
- data/gemfiles/rails_3.2.19.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.2.gemfile +1 -1
- data/gemfiles/rails_3.2.2.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.20.gemfile +1 -1
- data/gemfiles/rails_3.2.20.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.21.gemfile +1 -1
- data/gemfiles/rails_3.2.21.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.22.gemfile +8 -0
- data/gemfiles/rails_3.2.22.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.3.gemfile +1 -1
- data/gemfiles/rails_3.2.3.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.4.gemfile +1 -1
- data/gemfiles/rails_3.2.4.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.5.gemfile +1 -1
- data/gemfiles/rails_3.2.5.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.6.gemfile +1 -1
- data/gemfiles/rails_3.2.6.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.7.gemfile +1 -1
- data/gemfiles/rails_3.2.7.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.8.gemfile +1 -1
- data/gemfiles/rails_3.2.8.gemfile.lock +47 -0
- data/gemfiles/rails_3.2.9.gemfile +1 -1
- data/gemfiles/rails_3.2.9.gemfile.lock +47 -0
- data/gemfiles/rails_4.0.0.gemfile +1 -2
- data/gemfiles/rails_4.0.0.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.1.gemfile +1 -2
- data/gemfiles/rails_4.0.1.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.10.gemfile +1 -2
- data/gemfiles/rails_4.0.10.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.11.1.gemfile +1 -2
- data/gemfiles/rails_4.0.11.1.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.11.gemfile +1 -2
- data/gemfiles/rails_4.0.11.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.12.gemfile +1 -2
- data/gemfiles/rails_4.0.12.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.13.gemfile +1 -2
- data/gemfiles/rails_4.0.13.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.2.gemfile +1 -2
- data/gemfiles/rails_4.0.2.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.3.gemfile +1 -2
- data/gemfiles/rails_4.0.3.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.4.gemfile +1 -2
- data/gemfiles/rails_4.0.4.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.5.gemfile +1 -2
- data/gemfiles/rails_4.0.5.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.6.gemfile +1 -2
- data/gemfiles/rails_4.0.6.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.7.gemfile +1 -2
- data/gemfiles/rails_4.0.7.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.8.gemfile +1 -2
- data/gemfiles/rails_4.0.8.gemfile.lock +52 -0
- data/gemfiles/rails_4.0.9.gemfile +1 -2
- data/gemfiles/rails_4.0.9.gemfile.lock +52 -0
- data/gemfiles/rails_4.1.0.gemfile +1 -2
- data/gemfiles/rails_4.1.0.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.1.gemfile +1 -2
- data/gemfiles/rails_4.1.1.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.10.gemfile +7 -0
- data/gemfiles/rails_4.1.10.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.11.gemfile +7 -0
- data/gemfiles/rails_4.1.11.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.12.gemfile +7 -0
- data/gemfiles/rails_4.1.12.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.2.gemfile +1 -2
- data/gemfiles/rails_4.1.2.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.3.gemfile +1 -2
- data/gemfiles/rails_4.1.3.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.4.gemfile +1 -2
- data/gemfiles/rails_4.1.4.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.5.gemfile +1 -2
- data/gemfiles/rails_4.1.5.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.6.gemfile +1 -2
- data/gemfiles/rails_4.1.6.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.7.1.gemfile +1 -2
- data/gemfiles/rails_4.1.7.1.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.7.gemfile +1 -2
- data/gemfiles/rails_4.1.7.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.8.gemfile +1 -2
- data/gemfiles/rails_4.1.8.gemfile.lock +51 -0
- data/gemfiles/rails_4.1.9.gemfile +1 -2
- data/gemfiles/rails_4.1.9.gemfile.lock +51 -0
- data/gemfiles/rails_4.2.0.gemfile +7 -0
- data/gemfiles/rails_4.2.0.gemfile.lock +51 -0
- data/gemfiles/rails_4.2.1.gemfile +7 -0
- data/gemfiles/rails_4.2.1.gemfile.lock +51 -0
- data/gemfiles/rails_4.2.2.gemfile +7 -0
- data/gemfiles/rails_4.2.2.gemfile.lock +51 -0
- data/gemfiles/rails_4.2.3.gemfile +7 -0
- data/gemfiles/rails_4.2.3.gemfile.lock +51 -0
- data/lib/store_base_sti_class/version.rb +1 -1
- data/lib/store_base_sti_class.rb +2 -0
- data/lib/store_base_sti_class_for_3_0.rb +1 -1
- data/lib/store_base_sti_class_for_4_2.rb +271 -0
- data/store_base_sti_class.gemspec +2 -2
- data/storebasestiname_unittest.sql +0 -0
- metadata +98 -7
- data/CHANGELOG +0 -2
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
store_base_sti_class (0.3.0)
|
5
|
+
activerecord (>= 3.0.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.2.3)
|
11
|
+
activesupport (= 4.2.3)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activerecord (4.2.3)
|
14
|
+
activemodel (= 4.2.3)
|
15
|
+
activesupport (= 4.2.3)
|
16
|
+
arel (~> 6.0)
|
17
|
+
activesupport (4.2.3)
|
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.0.2)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
arel (6.0.2)
|
28
|
+
builder (3.2.2)
|
29
|
+
i18n (0.7.0)
|
30
|
+
json (1.8.3)
|
31
|
+
minitest (5.7.0)
|
32
|
+
rake (10.4.2)
|
33
|
+
sqlite3 (1.3.10)
|
34
|
+
thor (0.19.1)
|
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.3)
|
44
|
+
appraisal
|
45
|
+
bundler
|
46
|
+
minitest (>= 4.0)
|
47
|
+
sqlite3
|
48
|
+
store_base_sti_class!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.10.5
|
data/lib/store_base_sti_class.rb
CHANGED
@@ -8,6 +8,8 @@ elsif ActiveRecord::VERSION::STRING =~ /^4\.0/
|
|
8
8
|
require 'store_base_sti_class_for_4_0'
|
9
9
|
elsif ActiveRecord::VERSION::STRING =~ /^4\.1/
|
10
10
|
require 'store_base_sti_class_for_4_1'
|
11
|
+
elsif ActiveRecord::VERSION::STRING =~ /^4\.2/
|
12
|
+
require 'store_base_sti_class_for_4_2'
|
11
13
|
end
|
12
14
|
|
13
15
|
module StoreBaseSTIClass
|
@@ -0,0 +1,271 @@
|
|
1
|
+
if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
2
|
+
module ActiveRecord
|
3
|
+
|
4
|
+
class Base
|
5
|
+
class_attribute :store_base_sti_class
|
6
|
+
self.store_base_sti_class = true
|
7
|
+
end
|
8
|
+
|
9
|
+
module Associations
|
10
|
+
class Association
|
11
|
+
|
12
|
+
def creation_attributes
|
13
|
+
attributes = {}
|
14
|
+
|
15
|
+
if (reflection.has_one? || reflection.collection?) && !options[:through]
|
16
|
+
attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key]
|
17
|
+
|
18
|
+
if reflection.options[:as]
|
19
|
+
# START PATCH
|
20
|
+
# original:
|
21
|
+
# attributes[reflection.type] = owner.class.base_class.name
|
22
|
+
|
23
|
+
attributes[reflection.type] = ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name
|
24
|
+
# END PATCH
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
attributes
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class BelongsToPolymorphicAssociation
|
33
|
+
private
|
34
|
+
|
35
|
+
def replace_keys(record)
|
36
|
+
super
|
37
|
+
|
38
|
+
# START PATCH
|
39
|
+
# original:
|
40
|
+
# owner[reflection.foreign_type] = record.class.base_class.name
|
41
|
+
|
42
|
+
owner[reflection.foreign_type] = ActiveRecord::Base.store_base_sti_class ? record.class.base_class.name : record.class.name
|
43
|
+
|
44
|
+
# END PATCH
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Preloader
|
49
|
+
class Association
|
50
|
+
|
51
|
+
def build_scope
|
52
|
+
scope = klass.unscoped
|
53
|
+
|
54
|
+
values = reflection_scope.values
|
55
|
+
reflection_binds = reflection_scope.bind_values
|
56
|
+
preload_values = preload_scope.values
|
57
|
+
preload_binds = preload_scope.bind_values
|
58
|
+
|
59
|
+
scope.where_values = Array(values[:where]) + Array(preload_values[:where])
|
60
|
+
scope.references_values = Array(values[:references]) + Array(preload_values[:references])
|
61
|
+
scope.bind_values = (reflection_binds + preload_binds)
|
62
|
+
|
63
|
+
scope._select! preload_values[:select] || values[:select] || table[Arel.star]
|
64
|
+
scope.includes! preload_values[:includes] || values[:includes]
|
65
|
+
scope.joins! preload_values[:joins] || values[:joins]
|
66
|
+
scope.order! preload_values[:order] || values[:order]
|
67
|
+
|
68
|
+
if preload_values[:readonly] || values[:readonly]
|
69
|
+
scope.readonly!
|
70
|
+
end
|
71
|
+
|
72
|
+
if options[:as]
|
73
|
+
# START PATCH
|
74
|
+
# original:
|
75
|
+
# scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name })
|
76
|
+
|
77
|
+
scope.where!(klass.table_name => { reflection.type => ActiveRecord::Base.store_base_sti_class ? model.base_class.sti_name : model.sti_name })
|
78
|
+
|
79
|
+
# END PATCH
|
80
|
+
end
|
81
|
+
|
82
|
+
scope.unscope_values = Array(values[:unscope])
|
83
|
+
klass.default_scoped.merge(scope)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module ThroughAssociation
|
88
|
+
private
|
89
|
+
|
90
|
+
def through_scope
|
91
|
+
scope = through_reflection.klass.unscoped
|
92
|
+
|
93
|
+
if options[:source_type]
|
94
|
+
# BEGIN PATCH
|
95
|
+
# original: scope.where! reflection.foreign_type => options[:source_type]
|
96
|
+
|
97
|
+
adjusted_foreign_type = if ActiveRecord::Base.store_base_sti_class
|
98
|
+
options[:source_type]
|
99
|
+
else
|
100
|
+
([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
|
101
|
+
end
|
102
|
+
|
103
|
+
scope.where! reflection.foreign_type => adjusted_foreign_type
|
104
|
+
|
105
|
+
# END PATCH
|
106
|
+
else
|
107
|
+
unless reflection_scope.where_values.empty?
|
108
|
+
scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
|
109
|
+
scope.where_values = reflection_scope.values[:where]
|
110
|
+
scope.bind_values = reflection_scope.bind_values
|
111
|
+
end
|
112
|
+
|
113
|
+
scope.references! reflection_scope.values[:references]
|
114
|
+
scope = scope.order reflection_scope.values[:order] if scope.eager_loading?
|
115
|
+
end
|
116
|
+
|
117
|
+
scope
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class AssociationScope
|
123
|
+
def self.get_bind_values(owner, chain)
|
124
|
+
binds = []
|
125
|
+
last_reflection = chain.last
|
126
|
+
|
127
|
+
binds << last_reflection.join_id_for(owner)
|
128
|
+
if last_reflection.type
|
129
|
+
# START PATCH
|
130
|
+
# original: binds << owner.class.base_class.name
|
131
|
+
binds << (ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name)
|
132
|
+
# END PATCH
|
133
|
+
end
|
134
|
+
|
135
|
+
chain.each_cons(2).each do |reflection, next_reflection|
|
136
|
+
if reflection.type
|
137
|
+
# START PATCH
|
138
|
+
# original: binds << next_reflection.klass.base_class.name
|
139
|
+
binds << (ActiveRecord::Base.store_base_sti_class ? next_reflection.klass.base_class.name : next_reflection.klass.name)
|
140
|
+
# END PATCH
|
141
|
+
end
|
142
|
+
end
|
143
|
+
binds
|
144
|
+
end
|
145
|
+
|
146
|
+
def next_chain_scope(scope, table, reflection, tracker, assoc_klass, foreign_table, next_reflection)
|
147
|
+
join_keys = reflection.join_keys(assoc_klass)
|
148
|
+
key = join_keys.key
|
149
|
+
foreign_key = join_keys.foreign_key
|
150
|
+
|
151
|
+
constraint = table[key].eq(foreign_table[foreign_key])
|
152
|
+
|
153
|
+
if reflection.type
|
154
|
+
# BEGIN PATCH
|
155
|
+
# original:
|
156
|
+
# value = next_reflection.klass.base_class.name
|
157
|
+
# bind_val = bind scope, table.table_name, reflection.type, value, tracker
|
158
|
+
# scope = scope.where(table[reflection.type].eq(bind_val))
|
159
|
+
if ActiveRecord::Base.store_base_sti_class
|
160
|
+
value = next_reflection.klass.base_class.name
|
161
|
+
bind_val = bind scope, table.table_name, reflection.type, value, tracker
|
162
|
+
scope = scope.where(table[reflection.type].eq(bind_val))
|
163
|
+
else
|
164
|
+
value = next_reflection.klass.name
|
165
|
+
klass = next_reflection.klass
|
166
|
+
scope = scope.where(table[reflection.type].in(([klass] + klass.descendants).map(&:name)))
|
167
|
+
end
|
168
|
+
# END PATCH
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
scope = scope.joins(join(foreign_table, constraint))
|
173
|
+
end
|
174
|
+
|
175
|
+
def last_chain_scope(scope, table, reflection, owner, tracker, assoc_klass)
|
176
|
+
join_keys = reflection.join_keys(assoc_klass)
|
177
|
+
key = join_keys.key
|
178
|
+
foreign_key = join_keys.foreign_key
|
179
|
+
|
180
|
+
bind_val = bind scope, table.table_name, key.to_s, owner[foreign_key], tracker
|
181
|
+
scope = scope.where(table[key].eq(bind_val))
|
182
|
+
|
183
|
+
if reflection.type
|
184
|
+
# BEGIN PATCH
|
185
|
+
# original: owner.class.base_class.name
|
186
|
+
value = ActiveRecord::Base.store_base_sti_class ? owner.class.base_class.name : owner.class.name
|
187
|
+
# END PATCH
|
188
|
+
bind_val = bind scope, table.table_name, reflection.type, value, tracker
|
189
|
+
scope = scope.where(table[reflection.type].eq(bind_val))
|
190
|
+
else
|
191
|
+
scope
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
module ThroughAssociation
|
198
|
+
def construct_join_attributes(*records)
|
199
|
+
ensure_mutable
|
200
|
+
|
201
|
+
if source_reflection.association_primary_key(reflection.klass) == reflection.klass.primary_key
|
202
|
+
join_attributes = { source_reflection.name => records }
|
203
|
+
else
|
204
|
+
join_attributes = {
|
205
|
+
source_reflection.foreign_key =>
|
206
|
+
records.map { |record|
|
207
|
+
record.send(source_reflection.association_primary_key(reflection.klass))
|
208
|
+
}
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
if options[:source_type]
|
213
|
+
|
214
|
+
# START PATCH
|
215
|
+
# original:
|
216
|
+
# join_attributes[source_reflection.foreign_type] =
|
217
|
+
# records.map { |record| record.class.base_class.name }
|
218
|
+
|
219
|
+
join_attributes[source_reflection.foreign_type] =
|
220
|
+
records.map { |record| ActiveRecord::Base.store_base_sti_class ? record.class.base_class.name : record.class.name }
|
221
|
+
|
222
|
+
# END PATCH
|
223
|
+
end
|
224
|
+
|
225
|
+
if records.count == 1
|
226
|
+
Hash[join_attributes.map { |k, v| [k, v.first] }]
|
227
|
+
else
|
228
|
+
join_attributes
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
module Reflection
|
237
|
+
class ThroughReflection
|
238
|
+
def scope_chain
|
239
|
+
@scope_chain ||= begin
|
240
|
+
scope_chain = source_reflection.scope_chain.map(&:dup)
|
241
|
+
|
242
|
+
# Add to it the scope from this reflection (if any)
|
243
|
+
scope_chain.first << scope if scope
|
244
|
+
|
245
|
+
through_scope_chain = through_reflection.scope_chain.map(&:dup)
|
246
|
+
|
247
|
+
if options[:source_type]
|
248
|
+
type = foreign_type
|
249
|
+
# START PATCH
|
250
|
+
# original: source_type = options[:source_type]
|
251
|
+
source_type = if ActiveRecord::Base.store_base_sti_class
|
252
|
+
options[:source_type]
|
253
|
+
else
|
254
|
+
([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
|
255
|
+
end
|
256
|
+
# END PATCH
|
257
|
+
through_scope_chain.first << lambda { |object|
|
258
|
+
where(type => source_type)
|
259
|
+
}
|
260
|
+
end
|
261
|
+
|
262
|
+
# Recursively fill out the rest of the array from the through reflection
|
263
|
+
scope_chain + through_scope_chain
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
@@ -13,14 +13,14 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.email = "andrew.mutz@appfolio.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
|
-
"README.
|
16
|
+
"README.md"
|
17
17
|
]
|
18
18
|
s.files = Dir['**/*'].reject{ |f| f[%r{^pkg/}] || f[%r{^test/}] }
|
19
19
|
|
20
20
|
s.homepage = "http://github.com/appfolio/store_base_sti_class"
|
21
21
|
s.licenses = ["MIT"]
|
22
22
|
s.rubygems_version = "2.2.2"
|
23
|
-
s.summary = "Modifies ActiveRecord 3.0.5 - 4.
|
23
|
+
s.summary = "Modifies ActiveRecord 3.0.5 - 4.2.x with the ability to store the actual class (instead of the base class) in polymorhic _type columns when using STI"
|
24
24
|
|
25
25
|
s.add_runtime_dependency(%q<activerecord>, [">= 3.0.5"])
|
26
26
|
s.add_development_dependency(%q<minitest>, [">= 4.0"])
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_base_sti_class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Mutz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -90,99 +90,190 @@ executables: []
|
|
90
90
|
extensions: []
|
91
91
|
extra_rdoc_files:
|
92
92
|
- LICENSE.txt
|
93
|
-
- README.
|
93
|
+
- README.md
|
94
94
|
files:
|
95
95
|
- Appraisals
|
96
|
-
- CHANGELOG
|
97
96
|
- Gemfile
|
98
97
|
- Gemfile.lock
|
99
98
|
- LICENSE.txt
|
100
|
-
- README.
|
99
|
+
- README.md
|
101
100
|
- Rakefile
|
102
101
|
- debug.log
|
103
102
|
- gemfiles/rails_3.0.10.gemfile
|
103
|
+
- gemfiles/rails_3.0.10.gemfile.lock
|
104
104
|
- gemfiles/rails_3.0.11.gemfile
|
105
|
+
- gemfiles/rails_3.0.11.gemfile.lock
|
105
106
|
- gemfiles/rails_3.0.12.gemfile
|
107
|
+
- gemfiles/rails_3.0.12.gemfile.lock
|
106
108
|
- gemfiles/rails_3.0.13.gemfile
|
109
|
+
- gemfiles/rails_3.0.13.gemfile.lock
|
107
110
|
- gemfiles/rails_3.0.14.gemfile
|
111
|
+
- gemfiles/rails_3.0.14.gemfile.lock
|
108
112
|
- gemfiles/rails_3.0.15.gemfile
|
113
|
+
- gemfiles/rails_3.0.15.gemfile.lock
|
109
114
|
- gemfiles/rails_3.0.16.gemfile
|
115
|
+
- gemfiles/rails_3.0.16.gemfile.lock
|
110
116
|
- gemfiles/rails_3.0.17.gemfile
|
117
|
+
- gemfiles/rails_3.0.17.gemfile.lock
|
111
118
|
- gemfiles/rails_3.0.18.gemfile
|
119
|
+
- gemfiles/rails_3.0.18.gemfile.lock
|
112
120
|
- gemfiles/rails_3.0.19.gemfile
|
121
|
+
- gemfiles/rails_3.0.19.gemfile.lock
|
113
122
|
- gemfiles/rails_3.0.20.gemfile
|
123
|
+
- gemfiles/rails_3.0.20.gemfile.lock
|
114
124
|
- gemfiles/rails_3.0.5.gemfile
|
115
125
|
- gemfiles/rails_3.0.5.gemfile.lock
|
116
126
|
- gemfiles/rails_3.0.6.gemfile
|
127
|
+
- gemfiles/rails_3.0.6.gemfile.lock
|
117
128
|
- gemfiles/rails_3.0.7.gemfile
|
129
|
+
- gemfiles/rails_3.0.7.gemfile.lock
|
118
130
|
- gemfiles/rails_3.0.8.gemfile
|
131
|
+
- gemfiles/rails_3.0.8.gemfile.lock
|
119
132
|
- gemfiles/rails_3.0.9.gemfile
|
133
|
+
- gemfiles/rails_3.0.9.gemfile.lock
|
120
134
|
- gemfiles/rails_3.1.0.gemfile
|
135
|
+
- gemfiles/rails_3.1.0.gemfile.lock
|
121
136
|
- gemfiles/rails_3.1.10.gemfile
|
137
|
+
- gemfiles/rails_3.1.10.gemfile.lock
|
122
138
|
- gemfiles/rails_3.1.11.gemfile
|
139
|
+
- gemfiles/rails_3.1.11.gemfile.lock
|
123
140
|
- gemfiles/rails_3.1.12.gemfile
|
141
|
+
- gemfiles/rails_3.1.12.gemfile.lock
|
124
142
|
- gemfiles/rails_3.1.2.gemfile
|
143
|
+
- gemfiles/rails_3.1.2.gemfile.lock
|
125
144
|
- gemfiles/rails_3.1.3.gemfile
|
145
|
+
- gemfiles/rails_3.1.3.gemfile.lock
|
126
146
|
- gemfiles/rails_3.1.4.gemfile
|
147
|
+
- gemfiles/rails_3.1.4.gemfile.lock
|
127
148
|
- gemfiles/rails_3.1.5.gemfile
|
149
|
+
- gemfiles/rails_3.1.5.gemfile.lock
|
128
150
|
- gemfiles/rails_3.1.6.gemfile
|
151
|
+
- gemfiles/rails_3.1.6.gemfile.lock
|
129
152
|
- gemfiles/rails_3.1.7.gemfile
|
153
|
+
- gemfiles/rails_3.1.7.gemfile.lock
|
130
154
|
- gemfiles/rails_3.1.8.gemfile
|
155
|
+
- gemfiles/rails_3.1.8.gemfile.lock
|
131
156
|
- gemfiles/rails_3.1.9.gemfile
|
157
|
+
- gemfiles/rails_3.1.9.gemfile.lock
|
132
158
|
- gemfiles/rails_3.2.0.gemfile
|
159
|
+
- gemfiles/rails_3.2.0.gemfile.lock
|
133
160
|
- gemfiles/rails_3.2.1.gemfile
|
161
|
+
- gemfiles/rails_3.2.1.gemfile.lock
|
134
162
|
- gemfiles/rails_3.2.10.gemfile
|
163
|
+
- gemfiles/rails_3.2.10.gemfile.lock
|
135
164
|
- gemfiles/rails_3.2.11.gemfile
|
165
|
+
- gemfiles/rails_3.2.11.gemfile.lock
|
136
166
|
- gemfiles/rails_3.2.12.gemfile
|
167
|
+
- gemfiles/rails_3.2.12.gemfile.lock
|
137
168
|
- gemfiles/rails_3.2.13.gemfile
|
169
|
+
- gemfiles/rails_3.2.13.gemfile.lock
|
138
170
|
- gemfiles/rails_3.2.14.gemfile
|
171
|
+
- gemfiles/rails_3.2.14.gemfile.lock
|
139
172
|
- gemfiles/rails_3.2.15.gemfile
|
173
|
+
- gemfiles/rails_3.2.15.gemfile.lock
|
140
174
|
- gemfiles/rails_3.2.16.gemfile
|
175
|
+
- gemfiles/rails_3.2.16.gemfile.lock
|
141
176
|
- gemfiles/rails_3.2.17.gemfile
|
177
|
+
- gemfiles/rails_3.2.17.gemfile.lock
|
142
178
|
- gemfiles/rails_3.2.18.gemfile
|
179
|
+
- gemfiles/rails_3.2.18.gemfile.lock
|
143
180
|
- gemfiles/rails_3.2.19.gemfile
|
181
|
+
- gemfiles/rails_3.2.19.gemfile.lock
|
144
182
|
- gemfiles/rails_3.2.2.gemfile
|
183
|
+
- gemfiles/rails_3.2.2.gemfile.lock
|
145
184
|
- gemfiles/rails_3.2.20.gemfile
|
185
|
+
- gemfiles/rails_3.2.20.gemfile.lock
|
146
186
|
- gemfiles/rails_3.2.21.gemfile
|
187
|
+
- gemfiles/rails_3.2.21.gemfile.lock
|
188
|
+
- gemfiles/rails_3.2.22.gemfile
|
189
|
+
- gemfiles/rails_3.2.22.gemfile.lock
|
147
190
|
- gemfiles/rails_3.2.3.gemfile
|
191
|
+
- gemfiles/rails_3.2.3.gemfile.lock
|
148
192
|
- gemfiles/rails_3.2.4.gemfile
|
193
|
+
- gemfiles/rails_3.2.4.gemfile.lock
|
149
194
|
- gemfiles/rails_3.2.5.gemfile
|
195
|
+
- gemfiles/rails_3.2.5.gemfile.lock
|
150
196
|
- gemfiles/rails_3.2.6.gemfile
|
197
|
+
- gemfiles/rails_3.2.6.gemfile.lock
|
151
198
|
- gemfiles/rails_3.2.7.gemfile
|
199
|
+
- gemfiles/rails_3.2.7.gemfile.lock
|
152
200
|
- gemfiles/rails_3.2.8.gemfile
|
201
|
+
- gemfiles/rails_3.2.8.gemfile.lock
|
153
202
|
- gemfiles/rails_3.2.9.gemfile
|
203
|
+
- gemfiles/rails_3.2.9.gemfile.lock
|
154
204
|
- gemfiles/rails_4.0.0.gemfile
|
205
|
+
- gemfiles/rails_4.0.0.gemfile.lock
|
155
206
|
- gemfiles/rails_4.0.1.gemfile
|
207
|
+
- gemfiles/rails_4.0.1.gemfile.lock
|
156
208
|
- gemfiles/rails_4.0.10.gemfile
|
209
|
+
- gemfiles/rails_4.0.10.gemfile.lock
|
157
210
|
- gemfiles/rails_4.0.11.1.gemfile
|
211
|
+
- gemfiles/rails_4.0.11.1.gemfile.lock
|
158
212
|
- gemfiles/rails_4.0.11.gemfile
|
213
|
+
- gemfiles/rails_4.0.11.gemfile.lock
|
159
214
|
- gemfiles/rails_4.0.12.gemfile
|
215
|
+
- gemfiles/rails_4.0.12.gemfile.lock
|
160
216
|
- gemfiles/rails_4.0.13.gemfile
|
217
|
+
- gemfiles/rails_4.0.13.gemfile.lock
|
161
218
|
- gemfiles/rails_4.0.2.gemfile
|
219
|
+
- gemfiles/rails_4.0.2.gemfile.lock
|
162
220
|
- gemfiles/rails_4.0.3.gemfile
|
221
|
+
- gemfiles/rails_4.0.3.gemfile.lock
|
163
222
|
- gemfiles/rails_4.0.4.gemfile
|
223
|
+
- gemfiles/rails_4.0.4.gemfile.lock
|
164
224
|
- gemfiles/rails_4.0.5.gemfile
|
225
|
+
- gemfiles/rails_4.0.5.gemfile.lock
|
165
226
|
- gemfiles/rails_4.0.6.gemfile
|
227
|
+
- gemfiles/rails_4.0.6.gemfile.lock
|
166
228
|
- gemfiles/rails_4.0.7.gemfile
|
229
|
+
- gemfiles/rails_4.0.7.gemfile.lock
|
167
230
|
- gemfiles/rails_4.0.8.gemfile
|
231
|
+
- gemfiles/rails_4.0.8.gemfile.lock
|
168
232
|
- gemfiles/rails_4.0.9.gemfile
|
233
|
+
- gemfiles/rails_4.0.9.gemfile.lock
|
169
234
|
- gemfiles/rails_4.1.0.gemfile
|
235
|
+
- gemfiles/rails_4.1.0.gemfile.lock
|
170
236
|
- gemfiles/rails_4.1.1.gemfile
|
237
|
+
- gemfiles/rails_4.1.1.gemfile.lock
|
238
|
+
- gemfiles/rails_4.1.10.gemfile
|
239
|
+
- gemfiles/rails_4.1.10.gemfile.lock
|
240
|
+
- gemfiles/rails_4.1.11.gemfile
|
241
|
+
- gemfiles/rails_4.1.11.gemfile.lock
|
242
|
+
- gemfiles/rails_4.1.12.gemfile
|
243
|
+
- gemfiles/rails_4.1.12.gemfile.lock
|
171
244
|
- gemfiles/rails_4.1.2.gemfile
|
245
|
+
- gemfiles/rails_4.1.2.gemfile.lock
|
172
246
|
- gemfiles/rails_4.1.3.gemfile
|
247
|
+
- gemfiles/rails_4.1.3.gemfile.lock
|
173
248
|
- gemfiles/rails_4.1.4.gemfile
|
249
|
+
- gemfiles/rails_4.1.4.gemfile.lock
|
174
250
|
- gemfiles/rails_4.1.5.gemfile
|
251
|
+
- gemfiles/rails_4.1.5.gemfile.lock
|
175
252
|
- gemfiles/rails_4.1.6.gemfile
|
253
|
+
- gemfiles/rails_4.1.6.gemfile.lock
|
176
254
|
- gemfiles/rails_4.1.7.1.gemfile
|
255
|
+
- gemfiles/rails_4.1.7.1.gemfile.lock
|
177
256
|
- gemfiles/rails_4.1.7.gemfile
|
257
|
+
- gemfiles/rails_4.1.7.gemfile.lock
|
178
258
|
- gemfiles/rails_4.1.8.gemfile
|
259
|
+
- gemfiles/rails_4.1.8.gemfile.lock
|
179
260
|
- gemfiles/rails_4.1.9.gemfile
|
261
|
+
- gemfiles/rails_4.1.9.gemfile.lock
|
262
|
+
- gemfiles/rails_4.2.0.gemfile
|
263
|
+
- gemfiles/rails_4.2.0.gemfile.lock
|
264
|
+
- gemfiles/rails_4.2.1.gemfile
|
265
|
+
- gemfiles/rails_4.2.1.gemfile.lock
|
266
|
+
- gemfiles/rails_4.2.2.gemfile
|
267
|
+
- gemfiles/rails_4.2.2.gemfile.lock
|
268
|
+
- gemfiles/rails_4.2.3.gemfile
|
269
|
+
- gemfiles/rails_4.2.3.gemfile.lock
|
180
270
|
- lib/store_base_sti_class.rb
|
181
271
|
- lib/store_base_sti_class/version.rb
|
182
272
|
- lib/store_base_sti_class_for_3_0.rb
|
183
273
|
- lib/store_base_sti_class_for_3_1_and_above.rb
|
184
274
|
- lib/store_base_sti_class_for_4_0.rb
|
185
275
|
- lib/store_base_sti_class_for_4_1.rb
|
276
|
+
- lib/store_base_sti_class_for_4_2.rb
|
186
277
|
- store_base_sti_class.gemspec
|
187
278
|
- storebasestiname_unittest.sql
|
188
279
|
homepage: http://github.com/appfolio/store_base_sti_class
|
@@ -205,9 +296,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
296
|
version: '0'
|
206
297
|
requirements: []
|
207
298
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
299
|
+
rubygems_version: 2.4.3
|
209
300
|
signing_key:
|
210
301
|
specification_version: 4
|
211
|
-
summary: Modifies ActiveRecord 3.0.5 - 4.
|
302
|
+
summary: Modifies ActiveRecord 3.0.5 - 4.2.x with the ability to store the actual
|
212
303
|
class (instead of the base class) in polymorhic _type columns when using STI
|
213
304
|
test_files: []
|
data/CHANGELOG
DELETED