store_base_sti_class_for_3_0 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +10 -10
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/lib/store_base_sti_class_for_3_0.rb +2 -14
- data/store_base_sti_class_for_3_0.gemspec +5 -5
- data/test/models.rb +10 -0
- data/test/test_store_base_sti_class_for_3_0.rb +9 -0
- metadata +6 -6
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.0.
|
5
|
-
activesupport (= 3.0.
|
4
|
+
activemodel (3.0.6)
|
5
|
+
activesupport (= 3.0.6)
|
6
6
|
builder (~> 2.1.2)
|
7
|
-
i18n (~> 0.
|
8
|
-
activerecord (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
7
|
+
i18n (~> 0.5.0)
|
8
|
+
activerecord (3.0.6)
|
9
|
+
activemodel (= 3.0.6)
|
10
|
+
activesupport (= 3.0.6)
|
11
11
|
arel (~> 2.0.2)
|
12
12
|
tzinfo (~> 0.3.23)
|
13
|
-
activesupport (3.0.
|
14
|
-
arel (2.0.
|
13
|
+
activesupport (3.0.6)
|
14
|
+
arel (2.0.9)
|
15
15
|
builder (2.1.2)
|
16
16
|
git (1.2.5)
|
17
17
|
i18n (0.5.0)
|
@@ -22,13 +22,13 @@ GEM
|
|
22
22
|
mysql2 (0.2.6)
|
23
23
|
rake (0.8.7)
|
24
24
|
rcov (0.9.9)
|
25
|
-
tzinfo (0.3.
|
25
|
+
tzinfo (0.3.26)
|
26
26
|
|
27
27
|
PLATFORMS
|
28
28
|
ruby
|
29
29
|
|
30
30
|
DEPENDENCIES
|
31
|
-
activerecord (~> 3.0.
|
31
|
+
activerecord (~> 3.0.5)
|
32
32
|
bundler (~> 1.0.0)
|
33
33
|
jeweler (~> 1.5.2)
|
34
34
|
mysql2
|
data/README.rdoc
CHANGED
@@ -52,9 +52,9 @@ When changing this behavior you will have write a migration to update all of you
|
|
52
52
|
|
53
53
|
== Notes
|
54
54
|
|
55
|
-
The gem has been extracted out of https://github.com/pkmiec/rails/tree/store_base_sti_class_for_3_0_4 patch. It allows the functionality to be used in applications that include Rails as a gem.
|
55
|
+
The gem has been originally extracted out of https://github.com/pkmiec/rails/tree/store_base_sti_class_for_3_0_4 patch. It allows the functionality to be used in applications that include Rails as a gem.
|
56
56
|
|
57
|
-
|
57
|
+
Currently, it works with Rails ~= 3.0.5.
|
58
58
|
|
59
59
|
This gem will not work with Rails 3.1 as much of its ActiveRecord internals have been replaced with Arel. Similar but different changes need to be applied to Rails 3.1. Those changes will come.
|
60
60
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -123,18 +123,6 @@ module ActiveRecord
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
# Some databases impose a limit on the number of ids in a list (in Oracle its 1000)
|
127
|
-
# Make several smaller queries if necessary or make one query if the adapter supports it
|
128
|
-
def associated_records(ids)
|
129
|
-
# rails 3.0.4 introduced ids_in_list_limit
|
130
|
-
max_ids_in_a_list = (connection.respond_to?(:ids_in_list_limit) ? connection.ids_in_list_limit : nil) || ids.size
|
131
|
-
records = []
|
132
|
-
ids.each_slice(max_ids_in_a_list) do |some_ids|
|
133
|
-
records += yield(some_ids)
|
134
|
-
end
|
135
|
-
records
|
136
|
-
end
|
137
|
-
|
138
126
|
end
|
139
127
|
end
|
140
128
|
end
|
@@ -150,7 +138,7 @@ module ActiveRecord
|
|
150
138
|
|
151
139
|
case
|
152
140
|
when @reflection.options[:finder_sql]
|
153
|
-
@finder_sql =
|
141
|
+
@finder_sql = interpolate_and_sanitize_sql(@reflection.options[:finder_sql])
|
154
142
|
|
155
143
|
when @reflection.options[:as]
|
156
144
|
@finder_sql =
|
@@ -464,7 +452,7 @@ module ActiveRecord
|
|
464
452
|
|
465
453
|
[through_reflection, reflection].each do |ref|
|
466
454
|
if ref && ref.options[:conditions]
|
467
|
-
@join <<
|
455
|
+
@join << interpolate_and_sanitize_sql(ref.options[:conditions], aliased_table_name)
|
468
456
|
end
|
469
457
|
end
|
470
458
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{store_base_sti_class_for_3_0}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paul Kmiec"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-18}
|
13
13
|
s.description = %q{
|
14
14
|
ActiveRecord has always stored the base class in polymorphic _type columns when using STI. This can have non-trivial
|
15
15
|
performance implications in certain cases. This gem adds 'store_base_sti_class' configuration options which controls
|
@@ -55,20 +55,20 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.specification_version = 3
|
56
56
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
-
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.
|
58
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.5"])
|
59
59
|
s.add_runtime_dependency(%q<mysql2>, [">= 0"])
|
60
60
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
61
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
62
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
63
63
|
else
|
64
|
-
s.add_dependency(%q<activerecord>, ["~> 3.0.
|
64
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.5"])
|
65
65
|
s.add_dependency(%q<mysql2>, [">= 0"])
|
66
66
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
67
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
68
68
|
s.add_dependency(%q<rcov>, [">= 0"])
|
69
69
|
end
|
70
70
|
else
|
71
|
-
s.add_dependency(%q<activerecord>, ["~> 3.0.
|
71
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.5"])
|
72
72
|
s.add_dependency(%q<mysql2>, [">= 0"])
|
73
73
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
74
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/test/models.rb
CHANGED
@@ -32,6 +32,16 @@ class Tag < ActiveRecord::Base
|
|
32
32
|
|
33
33
|
has_many :polytaggings, :as => :polytag, :class_name => 'Tagging'
|
34
34
|
has_many :polytagged_posts, :through => :polytaggings, :source => :taggable, :source_type => 'Post'
|
35
|
+
|
36
|
+
has_many :authors, :class_name => "Author", :finder_sql => proc {
|
37
|
+
<<-SQL
|
38
|
+
SELECT authors.* FROM authors
|
39
|
+
INNER JOIN posts p ON authors.id = p.author_id
|
40
|
+
INNER JOIN taggings tgs ON tgs.taggable_id = p.id AND tgs.taggable_type = "Post"
|
41
|
+
WHERE tgs.tag_id = #{self.id}
|
42
|
+
SQL
|
43
|
+
}
|
44
|
+
|
35
45
|
end
|
36
46
|
|
37
47
|
class SpecialTag < Tag
|
@@ -130,4 +130,13 @@ class TestStoreBaseStiNameFor30 < ActiveRecord::TestCase
|
|
130
130
|
assert_equal post, tagging.taggable
|
131
131
|
end
|
132
132
|
|
133
|
+
def test_finder_sql_is_supported
|
134
|
+
author = Author.create!(:name => 'Bob')
|
135
|
+
post = Post.create!(:title => 'Budget Forecasts Bigger 2011 Deficit', :author => author)
|
136
|
+
special_tag = Tag.create!(:name => 'SpecialGeneral')
|
137
|
+
post.taggings.create(:tag => special_tag)
|
138
|
+
|
139
|
+
assert_equal [author], special_tag.authors
|
140
|
+
end
|
141
|
+
|
133
142
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Kmiec
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-18 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 13
|
31
31
|
segments:
|
32
32
|
- 3
|
33
33
|
- 0
|
34
|
-
-
|
35
|
-
version: 3.0.
|
34
|
+
- 5
|
35
|
+
version: 3.0.5
|
36
36
|
requirement: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
prerelease: false
|