store_base_sti_class 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +12 -0
- data/Gemfile.lock +15 -13
- data/gemfiles/rails_3.0.10.gemfile +1 -1
- data/gemfiles/rails_3.0.11.gemfile +1 -1
- data/gemfiles/rails_3.0.12.gemfile +1 -1
- data/gemfiles/rails_3.0.13.gemfile +1 -1
- data/gemfiles/rails_3.0.14.gemfile +1 -1
- data/gemfiles/rails_3.0.15.gemfile +1 -1
- data/gemfiles/rails_3.0.16.gemfile +1 -1
- data/gemfiles/rails_3.0.17.gemfile +1 -1
- data/gemfiles/rails_3.0.18.gemfile +1 -1
- data/gemfiles/rails_3.0.19.gemfile +1 -1
- data/gemfiles/rails_3.0.20.gemfile +1 -1
- data/gemfiles/rails_3.0.5.gemfile +1 -1
- data/gemfiles/rails_3.0.6.gemfile +1 -1
- data/gemfiles/rails_3.0.7.gemfile +1 -1
- data/gemfiles/rails_3.0.8.gemfile +1 -1
- data/gemfiles/rails_3.0.9.gemfile +1 -1
- data/gemfiles/rails_3.1.0.gemfile +1 -1
- data/gemfiles/rails_3.1.10.gemfile +1 -1
- data/gemfiles/rails_3.1.11.gemfile +1 -1
- data/gemfiles/rails_3.1.12.gemfile +1 -1
- data/gemfiles/rails_3.1.2.gemfile +1 -1
- data/gemfiles/rails_3.1.3.gemfile +1 -1
- data/gemfiles/rails_3.1.4.gemfile +1 -1
- data/gemfiles/rails_3.1.5.gemfile +1 -1
- data/gemfiles/rails_3.1.6.gemfile +1 -1
- data/gemfiles/rails_3.1.7.gemfile +1 -1
- data/gemfiles/rails_3.1.8.gemfile +1 -1
- data/gemfiles/rails_3.1.9.gemfile +1 -1
- data/gemfiles/rails_3.2.0.gemfile +1 -1
- data/gemfiles/rails_3.2.1.gemfile +1 -1
- data/gemfiles/rails_3.2.10.gemfile +1 -1
- data/gemfiles/rails_3.2.11.gemfile +1 -1
- data/gemfiles/rails_3.2.12.gemfile +1 -1
- data/gemfiles/rails_3.2.13.gemfile +1 -1
- data/gemfiles/rails_3.2.14.gemfile +1 -1
- data/gemfiles/rails_3.2.15.gemfile +1 -1
- data/gemfiles/rails_3.2.16.gemfile +1 -1
- data/gemfiles/rails_3.2.17.gemfile +1 -1
- data/gemfiles/rails_3.2.18.gemfile +1 -1
- data/gemfiles/rails_3.2.19.gemfile +1 -1
- data/gemfiles/rails_3.2.2.gemfile +1 -1
- data/gemfiles/rails_3.2.20.gemfile +1 -1
- data/gemfiles/rails_3.2.21.gemfile +1 -1
- data/gemfiles/rails_3.2.22.1.gemfile +8 -0
- data/gemfiles/rails_3.2.22.2.gemfile +8 -0
- data/gemfiles/rails_3.2.22.gemfile +1 -1
- data/gemfiles/rails_3.2.3.gemfile +1 -1
- data/gemfiles/rails_3.2.4.gemfile +1 -1
- data/gemfiles/rails_3.2.5.gemfile +1 -1
- data/gemfiles/rails_3.2.6.gemfile +1 -1
- data/gemfiles/rails_3.2.7.gemfile +1 -1
- data/gemfiles/rails_3.2.8.gemfile +1 -1
- data/gemfiles/rails_3.2.9.gemfile +1 -1
- data/gemfiles/rails_4.0.0.gemfile +1 -1
- data/gemfiles/rails_4.0.1.gemfile +1 -1
- data/gemfiles/rails_4.0.10.gemfile +1 -1
- data/gemfiles/rails_4.0.11.1.gemfile +1 -1
- data/gemfiles/rails_4.0.11.gemfile +1 -1
- data/gemfiles/rails_4.0.12.gemfile +1 -1
- data/gemfiles/rails_4.0.13.gemfile +1 -1
- data/gemfiles/rails_4.0.2.gemfile +1 -1
- data/gemfiles/rails_4.0.3.gemfile +1 -1
- data/gemfiles/rails_4.0.4.gemfile +1 -1
- data/gemfiles/rails_4.0.5.gemfile +1 -1
- data/gemfiles/rails_4.0.6.gemfile +1 -1
- data/gemfiles/rails_4.0.7.gemfile +1 -1
- data/gemfiles/rails_4.0.8.gemfile +1 -1
- data/gemfiles/rails_4.0.9.gemfile +1 -1
- data/gemfiles/rails_4.1.0.gemfile +1 -1
- data/gemfiles/rails_4.1.1.gemfile +1 -1
- data/gemfiles/rails_4.1.10.gemfile +1 -1
- data/gemfiles/rails_4.1.11.gemfile +1 -1
- data/gemfiles/rails_4.1.12.gemfile +1 -1
- data/gemfiles/rails_4.1.13.gemfile +7 -0
- data/gemfiles/rails_4.1.14.1.gemfile +7 -0
- data/gemfiles/rails_4.1.14.2.gemfile +7 -0
- data/gemfiles/rails_4.1.14.gemfile +7 -0
- data/gemfiles/rails_4.1.15.gemfile +7 -0
- data/gemfiles/rails_4.1.2.gemfile +1 -1
- data/gemfiles/rails_4.1.3.gemfile +1 -1
- data/gemfiles/rails_4.1.4.gemfile +1 -1
- data/gemfiles/rails_4.1.5.gemfile +1 -1
- data/gemfiles/rails_4.1.6.gemfile +1 -1
- data/gemfiles/rails_4.1.7.1.gemfile +1 -1
- data/gemfiles/rails_4.1.7.gemfile +1 -1
- data/gemfiles/rails_4.1.8.gemfile +1 -1
- data/gemfiles/rails_4.1.9.gemfile +1 -1
- data/gemfiles/rails_4.2.0.gemfile +1 -1
- data/gemfiles/rails_4.2.1.gemfile +1 -1
- data/gemfiles/rails_4.2.2.gemfile +1 -1
- data/gemfiles/rails_4.2.3.gemfile +1 -1
- data/gemfiles/rails_4.2.4.gemfile +7 -0
- data/gemfiles/rails_4.2.5.1.gemfile +7 -0
- data/gemfiles/rails_4.2.5.2.gemfile +7 -0
- data/gemfiles/rails_4.2.5.gemfile +7 -0
- data/gemfiles/rails_4.2.6.gemfile +7 -0
- data/lib/store_base_sti_class/version.rb +1 -1
- data/lib/store_base_sti_class_for_4_1.rb +6 -1
- data/lib/store_base_sti_class_for_4_2.rb +89 -0
- data/store_base_sti_class.gemspec +17 -17
- metadata +17 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aebf888bda436f1509dda482177d4e78d78961be
|
4
|
+
data.tar.gz: 1c1e2881ca2d9eb940a864f57a976cb5244ad6a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418e3959b01a05c5ea8a19d07f24297c476c164dcd79f87a88179035d491d0265861b0222da805145d08455ada68b6bec11d25788944fc75d52699bab09411ae
|
7
|
+
data.tar.gz: 43c594f62cfdfc1da1bc2c7b3b6da140c767f74eddc61874a0b883ed11d8d5c91a0a9b12ce0648203412d68c6798599cee629304ea4095ecae273d794b4eb407
|
data/Appraisals
CHANGED
@@ -50,6 +50,8 @@ RAILS_VERSIONS = %w(
|
|
50
50
|
3.2.20
|
51
51
|
3.2.21
|
52
52
|
3.2.22
|
53
|
+
3.2.22.1
|
54
|
+
3.2.22.2
|
53
55
|
4.0.0
|
54
56
|
4.0.1
|
55
57
|
4.0.2
|
@@ -79,10 +81,20 @@ RAILS_VERSIONS = %w(
|
|
79
81
|
4.1.10
|
80
82
|
4.1.11
|
81
83
|
4.1.12
|
84
|
+
4.1.13
|
85
|
+
4.1.14
|
86
|
+
4.1.14.1
|
87
|
+
4.1.14.2
|
88
|
+
4.1.15
|
82
89
|
4.2.0
|
83
90
|
4.2.1
|
84
91
|
4.2.2
|
85
92
|
4.2.3
|
93
|
+
4.2.4
|
94
|
+
4.2.5
|
95
|
+
4.2.5.1
|
96
|
+
4.2.5.2
|
97
|
+
4.2.6
|
86
98
|
)
|
87
99
|
|
88
100
|
RAILS_VERSIONS.each do |version|
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
store_base_sti_class (0.
|
4
|
+
store_base_sti_class (0.5.0)
|
5
5
|
activerecord (>= 3.0.5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (4.2.
|
11
|
-
activesupport (= 4.2.
|
10
|
+
activemodel (4.2.6)
|
11
|
+
activesupport (= 4.2.6)
|
12
12
|
builder (~> 3.1)
|
13
|
-
activerecord (4.2.
|
14
|
-
activemodel (= 4.2.
|
15
|
-
activesupport (= 4.2.
|
13
|
+
activerecord (4.2.6)
|
14
|
+
activemodel (= 4.2.6)
|
15
|
+
activesupport (= 4.2.6)
|
16
16
|
arel (~> 6.0)
|
17
|
-
activesupport (4.2.
|
17
|
+
activesupport (4.2.6)
|
18
18
|
i18n (~> 0.7)
|
19
19
|
json (~> 1.7, >= 1.7.7)
|
20
20
|
minitest (~> 5.1)
|
21
21
|
thread_safe (~> 0.3, >= 0.3.4)
|
22
22
|
tzinfo (~> 1.1)
|
23
|
-
appraisal (
|
23
|
+
appraisal (2.1.0)
|
24
24
|
bundler
|
25
25
|
rake
|
26
|
-
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
arel (6.0.3)
|
27
28
|
builder (3.2.2)
|
28
29
|
i18n (0.7.0)
|
29
30
|
json (1.8.3)
|
30
|
-
minitest (5.
|
31
|
-
rake (
|
32
|
-
sqlite3 (1.3.
|
31
|
+
minitest (5.8.4)
|
32
|
+
rake (11.1.2)
|
33
|
+
sqlite3 (1.3.11)
|
34
|
+
thor (0.19.1)
|
33
35
|
thread_safe (0.3.5)
|
34
36
|
tzinfo (1.2.2)
|
35
37
|
thread_safe (~> 0.1)
|
@@ -45,4 +47,4 @@ DEPENDENCIES
|
|
45
47
|
store_base_sti_class!
|
46
48
|
|
47
49
|
BUNDLED WITH
|
48
|
-
1.
|
50
|
+
1.11.2
|
@@ -65,7 +65,12 @@ if ActiveRecord::VERSION::STRING =~ /^4\.1/
|
|
65
65
|
end
|
66
66
|
scope_chain_index += 1
|
67
67
|
|
68
|
-
|
68
|
+
default_scope = if klass.method(:build_default_scope).arity == 0
|
69
|
+
klass.send(:build_default_scope)
|
70
|
+
else
|
71
|
+
klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))
|
72
|
+
end
|
73
|
+
scope_chain_items.concat [default_scope].compact
|
69
74
|
|
70
75
|
rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
|
71
76
|
left.merge right
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_record/associations/join_dependency/join_part'
|
2
|
+
|
1
3
|
if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
2
4
|
module ActiveRecord
|
3
5
|
|
@@ -29,6 +31,72 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
class JoinDependency # :nodoc:
|
35
|
+
class JoinAssociation < JoinPart # :nodoc:
|
36
|
+
def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scope_chain, chain)
|
37
|
+
joins = []
|
38
|
+
bind_values = []
|
39
|
+
tables = tables.reverse
|
40
|
+
|
41
|
+
scope_chain_index = 0
|
42
|
+
scope_chain = scope_chain.reverse
|
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 do |reflection|
|
47
|
+
table = tables.shift
|
48
|
+
klass = reflection.klass
|
49
|
+
|
50
|
+
join_keys = reflection.join_keys(klass)
|
51
|
+
key = join_keys.key
|
52
|
+
foreign_key = join_keys.foreign_key
|
53
|
+
|
54
|
+
constraint = build_constraint(klass, table, key, foreign_table, foreign_key)
|
55
|
+
|
56
|
+
scope_chain_items = scope_chain[scope_chain_index].map do |item|
|
57
|
+
if item.is_a?(Relation)
|
58
|
+
item
|
59
|
+
else
|
60
|
+
ActiveRecord::Relation.create(klass, table).instance_exec(node, &item)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
scope_chain_index += 1
|
64
|
+
|
65
|
+
scope_chain_items.concat [klass.send(:build_default_scope, ActiveRecord::Relation.create(klass, table))].compact
|
66
|
+
|
67
|
+
rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
|
68
|
+
left.merge right
|
69
|
+
end
|
70
|
+
|
71
|
+
if rel && !rel.arel.constraints.empty?
|
72
|
+
bind_values.concat rel.bind_values
|
73
|
+
constraint = constraint.and rel.arel.constraints
|
74
|
+
end
|
75
|
+
|
76
|
+
if reflection.type
|
77
|
+
# START PATCH
|
78
|
+
# original:
|
79
|
+
# value = foreign_klass.base_class.name
|
80
|
+
value = ActiveRecord::Base.store_base_sti_class ? foreign_klass.base_class.name : foreign_klass.name
|
81
|
+
# END PATCH
|
82
|
+
column = klass.columns_hash[reflection.type.to_s]
|
83
|
+
|
84
|
+
substitute = klass.connection.substitute_at(column)
|
85
|
+
bind_values.push [column, value]
|
86
|
+
constraint = constraint.and table[reflection.type].eq substitute
|
87
|
+
end
|
88
|
+
|
89
|
+
joins << table.create_join(table, table.create_on(constraint), join_type)
|
90
|
+
|
91
|
+
# The current table in this iteration becomes the foreign table in the next
|
92
|
+
foreign_table, foreign_klass = table, klass
|
93
|
+
end
|
94
|
+
|
95
|
+
JoinInformation.new joins, bind_values
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
32
100
|
class BelongsToPolymorphicAssociation
|
33
101
|
private
|
34
102
|
|
@@ -231,6 +299,27 @@ if ActiveRecord::VERSION::STRING =~ /^4\.2/
|
|
231
299
|
|
232
300
|
end
|
233
301
|
|
302
|
+
class HasManyThroughAssociation
|
303
|
+
|
304
|
+
def build_through_record(record)
|
305
|
+
@through_records[record.object_id] ||= begin
|
306
|
+
ensure_mutable
|
307
|
+
|
308
|
+
through_record = through_association.build(*options_for_through_record)
|
309
|
+
through_record.send("#{source_reflection.name}=", record)
|
310
|
+
|
311
|
+
# START PATCH
|
312
|
+
if ActiveRecord::Base.store_base_sti_class
|
313
|
+
if options[:source_type]
|
314
|
+
through_record.send("#{source_reflection.foreign_type}=", options[:source_type])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
# END PATCH
|
318
|
+
|
319
|
+
through_record
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
234
323
|
end
|
235
324
|
|
236
325
|
module Reflection
|
@@ -4,27 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'store_base_sti_class/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
7
|
+
s.name = 'store_base_sti_class'
|
8
8
|
s.version = StoreBaseSTIClass::VERSION
|
9
9
|
|
10
|
-
s.require_paths = [
|
11
|
-
s.authors = [
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
s.authors = ['AppFolio']
|
12
12
|
s.description = "\n ActiveRecord has always stored the base class in polymorphic _type columns when using STI. This can have non-trivial\n performance implications in certain cases. This gem adds 'store_base_sti_class' configuration options which controls\n whether ActiveRecord will store the base class or the actual class. Default to true for backwards compatibility.\n "
|
13
|
-
s.email =
|
14
|
-
s.extra_rdoc_files =
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
s.email = 'engineering@appfolio.com'
|
14
|
+
s.extra_rdoc_files = %w(
|
15
|
+
LICENSE.txt
|
16
|
+
README.md
|
17
|
+
)
|
18
18
|
s.files = Dir['**/*'].reject{ |f| f[%r{^pkg/}] || f[%r{^test/}] }
|
19
19
|
|
20
|
-
s.homepage =
|
21
|
-
s.licenses = [
|
22
|
-
s.rubygems_version =
|
23
|
-
s.summary =
|
20
|
+
s.homepage = 'http://github.com/appfolio/store_base_sti_class'
|
21
|
+
s.licenses = ['MIT']
|
22
|
+
s.rubygems_version = '2.2.2'
|
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
|
-
s.add_runtime_dependency(%q<activerecord>, [
|
26
|
-
s.add_development_dependency(%q<minitest>, [
|
27
|
-
s.add_development_dependency(%q<sqlite3>, [
|
28
|
-
s.add_development_dependency(%q<appraisal>, [
|
29
|
-
s.add_development_dependency(%q<bundler>, [
|
25
|
+
s.add_runtime_dependency(%q<activerecord>, ['>= 3.0.5'])
|
26
|
+
s.add_development_dependency(%q<minitest>, ['>= 4.0'])
|
27
|
+
s.add_development_dependency(%q<sqlite3>, ['>= 0'])
|
28
|
+
s.add_development_dependency(%q<appraisal>, ['>= 0'])
|
29
|
+
s.add_development_dependency(%q<bundler>, ['>= 0'])
|
30
30
|
end
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- AppFolio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -85,7 +85,7 @@ description: "\n ActiveRecord has always stored the base class in polymorphic
|
|
85
85
|
in certain cases. This gem adds 'store_base_sti_class' configuration options which
|
86
86
|
controls\n whether ActiveRecord will store the base class or the actual class.
|
87
87
|
Default to true for backwards compatibility.\n "
|
88
|
-
email:
|
88
|
+
email: engineering@appfolio.com
|
89
89
|
executables: []
|
90
90
|
extensions: []
|
91
91
|
extra_rdoc_files:
|
@@ -185,6 +185,8 @@ files:
|
|
185
185
|
- gemfiles/rails_3.2.20.gemfile.lock
|
186
186
|
- gemfiles/rails_3.2.21.gemfile
|
187
187
|
- gemfiles/rails_3.2.21.gemfile.lock
|
188
|
+
- gemfiles/rails_3.2.22.1.gemfile
|
189
|
+
- gemfiles/rails_3.2.22.2.gemfile
|
188
190
|
- gemfiles/rails_3.2.22.gemfile
|
189
191
|
- gemfiles/rails_3.2.22.gemfile.lock
|
190
192
|
- gemfiles/rails_3.2.3.gemfile
|
@@ -241,6 +243,11 @@ files:
|
|
241
243
|
- gemfiles/rails_4.1.11.gemfile.lock
|
242
244
|
- gemfiles/rails_4.1.12.gemfile
|
243
245
|
- gemfiles/rails_4.1.12.gemfile.lock
|
246
|
+
- gemfiles/rails_4.1.13.gemfile
|
247
|
+
- gemfiles/rails_4.1.14.1.gemfile
|
248
|
+
- gemfiles/rails_4.1.14.2.gemfile
|
249
|
+
- gemfiles/rails_4.1.14.gemfile
|
250
|
+
- gemfiles/rails_4.1.15.gemfile
|
244
251
|
- gemfiles/rails_4.1.2.gemfile
|
245
252
|
- gemfiles/rails_4.1.2.gemfile.lock
|
246
253
|
- gemfiles/rails_4.1.3.gemfile
|
@@ -267,6 +274,11 @@ files:
|
|
267
274
|
- gemfiles/rails_4.2.2.gemfile.lock
|
268
275
|
- gemfiles/rails_4.2.3.gemfile
|
269
276
|
- gemfiles/rails_4.2.3.gemfile.lock
|
277
|
+
- gemfiles/rails_4.2.4.gemfile
|
278
|
+
- gemfiles/rails_4.2.5.1.gemfile
|
279
|
+
- gemfiles/rails_4.2.5.2.gemfile
|
280
|
+
- gemfiles/rails_4.2.5.gemfile
|
281
|
+
- gemfiles/rails_4.2.6.gemfile
|
270
282
|
- lib/store_base_sti_class.rb
|
271
283
|
- lib/store_base_sti_class/version.rb
|
272
284
|
- lib/store_base_sti_class_for_3_0.rb
|
@@ -296,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
296
308
|
version: '0'
|
297
309
|
requirements: []
|
298
310
|
rubyforge_project:
|
299
|
-
rubygems_version: 2.4.
|
311
|
+
rubygems_version: 2.4.5.1
|
300
312
|
signing_key:
|
301
313
|
specification_version: 4
|
302
314
|
summary: Modifies ActiveRecord 3.0.5 - 4.2.x with the ability to store the actual
|