mongoid-eager-loading 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore
CHANGED
@@ -47,7 +47,7 @@ module Mongoid
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def setup_associations_with_ids(documents, reflection, one
|
50
|
+
def setup_associations_with_ids(documents, reflection, one)
|
51
51
|
ids = association_ids(documents, reflection)
|
52
52
|
|
53
53
|
ignore_includes
|
@@ -56,7 +56,7 @@ module Mongoid
|
|
56
56
|
add_id_association(eager_association.send(reflection.foreign_key), eager_association)
|
57
57
|
end
|
58
58
|
|
59
|
-
assign_associations(documents, reflection)
|
59
|
+
assign_associations(documents, reflection, one)
|
60
60
|
end
|
61
61
|
|
62
62
|
def setup_associations_with_foreign_keys(documents, reflection, one)
|
@@ -68,7 +68,7 @@ module Mongoid
|
|
68
68
|
add_id_association(eager_association.id, eager_association)
|
69
69
|
end
|
70
70
|
|
71
|
-
assign_associations(documents, reflection)
|
71
|
+
assign_associations(documents, reflection, one)
|
72
72
|
end
|
73
73
|
|
74
74
|
def association_ids(documents, reflection)
|
@@ -84,15 +84,15 @@ module Mongoid
|
|
84
84
|
ids
|
85
85
|
end
|
86
86
|
|
87
|
-
def assign_associations(documents, reflection)
|
87
|
+
def assign_associations(documents, reflection, one)
|
88
88
|
id_documents_map.each do |id, documents|
|
89
89
|
documents.each do |document|
|
90
90
|
key_value = document.send(reflection.key)
|
91
91
|
associations = \
|
92
|
-
if
|
93
|
-
key_value.collect { |v| id_associations_map[v] }
|
94
|
-
else
|
92
|
+
if one
|
95
93
|
id_associations_map[key_value] ? id_associations_map[key_value].first : nil
|
94
|
+
else
|
95
|
+
to_array(key_value).collect { |v| id_associations_map[v] }.compact.flatten
|
96
96
|
end
|
97
97
|
document.instance_variable_set("@#{reflection.name}", associations)
|
98
98
|
end
|
@@ -34,13 +34,13 @@ describe Mongoid::Criterion::EagerLoading do
|
|
34
34
|
|
35
35
|
@post1 = @person1.posts.create(:title => "post1")
|
36
36
|
@post2 = @person1.posts.create(:title => "post2")
|
37
|
-
@post3 = @
|
37
|
+
@post3 = @person1.posts.create(:title => "post3")
|
38
38
|
@post4 = @person2.posts.create(:title => "post4")
|
39
39
|
@post5 = Post.create(:title => "post5")
|
40
40
|
|
41
41
|
@preference1 = @person1.preferences.create(:name => "preference1")
|
42
42
|
@preference2 = @person1.preferences.create(:name => "preference2")
|
43
|
-
@preference3 = @
|
43
|
+
@preference3 = @person1.preferences.create(:name => "preference3")
|
44
44
|
@preference4 = @person2.preferences.create(:name => "preference4")
|
45
45
|
@preference5 = Preference.create(:name => "preference5")
|
46
46
|
end
|
@@ -82,12 +82,12 @@ describe Mongoid::Criterion::EagerLoading do
|
|
82
82
|
id_documents_map[@person3.id].should == [@person3]
|
83
83
|
|
84
84
|
id_associations_map = criteria.send(:id_associations_map)
|
85
|
-
id_associations_map[@person1.id].should == [@post1, @post2]
|
86
|
-
id_associations_map[@person2.id].should == [@
|
85
|
+
id_associations_map[@person1.id].should == [@post1, @post2, @post3]
|
86
|
+
id_associations_map[@person2.id].should == [@post4]
|
87
87
|
id_associations_map[@person3.id].should == nil
|
88
88
|
|
89
|
-
@person1.posts.should == [@post1, @post2]
|
90
|
-
@person2.posts.should == [@
|
89
|
+
@person1.posts.should == [@post1, @post2, @post3]
|
90
|
+
@person2.posts.should == [@post4]
|
91
91
|
@person3.posts.should == []
|
92
92
|
end
|
93
93
|
|
@@ -102,7 +102,7 @@ describe Mongoid::Criterion::EagerLoading do
|
|
102
102
|
id_documents_map = criteria.send(:id_documents_map)
|
103
103
|
id_documents_map[@preference1.id].should == [@person1]
|
104
104
|
id_documents_map[@preference2.id].should == [@person1]
|
105
|
-
id_documents_map[@preference3.id].should == [@
|
105
|
+
id_documents_map[@preference3.id].should == [@person1]
|
106
106
|
id_documents_map[@preference4.id].should == [@person2]
|
107
107
|
id_documents_map[@preference5.id].should == nil
|
108
108
|
|
@@ -113,8 +113,8 @@ describe Mongoid::Criterion::EagerLoading do
|
|
113
113
|
id_associations_map[@preference4.id].should == [@preference4]
|
114
114
|
id_associations_map[@preference5.id].should == nil
|
115
115
|
|
116
|
-
@person1.preferences.should == [@preference1, @preference2]
|
117
|
-
@person2.preferences.should == [@
|
116
|
+
@person1.preferences.should == [@preference1, @preference2, @preference3]
|
117
|
+
@person2.preferences.should == [@preference4]
|
118
118
|
@person3.preferences.should == []
|
119
119
|
end
|
120
120
|
|
@@ -151,8 +151,8 @@ describe Mongoid::Criterion::EagerLoading do
|
|
151
151
|
criteria.preload(posts)
|
152
152
|
|
153
153
|
id_documents_map = criteria.send(:id_documents_map)
|
154
|
-
id_documents_map[@person1.id].should == [@post1, @post2]
|
155
|
-
id_documents_map[@person2.id].should == [@
|
154
|
+
id_documents_map[@person1.id].should == [@post1, @post2, @post3]
|
155
|
+
id_documents_map[@person2.id].should == [@post4]
|
156
156
|
id_documents_map[@person3.id].should == nil
|
157
157
|
|
158
158
|
id_associations_map = criteria.send(:id_associations_map)
|
@@ -162,10 +162,26 @@ describe Mongoid::Criterion::EagerLoading do
|
|
162
162
|
|
163
163
|
@post1.person.should == @person1
|
164
164
|
@post2.person.should == @person1
|
165
|
-
@post3.person.should == @
|
165
|
+
@post3.person.should == @person1
|
166
166
|
@post4.person.should == @person2
|
167
167
|
@post5.person.should == nil
|
168
168
|
end
|
169
169
|
end
|
170
|
+
|
171
|
+
it "preload references_many association" do
|
172
|
+
people = Person.all.to_a
|
173
|
+
posts = Post.all.to_a
|
174
|
+
|
175
|
+
criteria = Mongoid::Criteria.new(Person)
|
176
|
+
|
177
|
+
criteria.each do |person|
|
178
|
+
person.posts.should be_an_instance_of Array
|
179
|
+
person.posts.each {|p| p.should be_an_instance_of Post}
|
180
|
+
end
|
181
|
+
criteria.includes(:posts).all.each do |person|
|
182
|
+
person.posts.should be_an_instance_of Array
|
183
|
+
person.posts.each {|p| p.should be_an_instance_of Post}
|
184
|
+
end
|
185
|
+
end
|
170
186
|
end
|
171
187
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-eager-loading
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-24 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -158,7 +158,6 @@ files:
|
|
158
158
|
- .rvmrc.example
|
159
159
|
- .watchr
|
160
160
|
- Gemfile
|
161
|
-
- Gemfile.lock
|
162
161
|
- LICENSE
|
163
162
|
- README.md
|
164
163
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mongoid-eager-loading (0.3.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activemodel (3.0.3)
|
10
|
-
activesupport (= 3.0.3)
|
11
|
-
builder (~> 2.1.2)
|
12
|
-
i18n (~> 0.4)
|
13
|
-
activesupport (3.0.3)
|
14
|
-
bson (1.2.0)
|
15
|
-
bson_ext (1.2.0)
|
16
|
-
builder (2.1.2)
|
17
|
-
diff-lcs (1.1.2)
|
18
|
-
i18n (0.5.0)
|
19
|
-
mocha (0.9.9)
|
20
|
-
rake
|
21
|
-
mongo (1.2.0)
|
22
|
-
bson (>= 1.2.0)
|
23
|
-
mongoid (2.0.0.rc.6)
|
24
|
-
activemodel (~> 3.0)
|
25
|
-
mongo (~> 1.2)
|
26
|
-
tzinfo (~> 0.3.22)
|
27
|
-
will_paginate (~> 3.0.pre)
|
28
|
-
rake (0.8.7)
|
29
|
-
rspec (2.0.1)
|
30
|
-
rspec-core (~> 2.0.1)
|
31
|
-
rspec-expectations (~> 2.0.1)
|
32
|
-
rspec-mocks (~> 2.0.1)
|
33
|
-
rspec-core (2.0.1)
|
34
|
-
rspec-expectations (2.0.1)
|
35
|
-
diff-lcs (>= 1.1.2)
|
36
|
-
rspec-mocks (2.0.1)
|
37
|
-
rspec-core (~> 2.0.1)
|
38
|
-
rspec-expectations (~> 2.0.1)
|
39
|
-
tzinfo (0.3.24)
|
40
|
-
watchr (0.7)
|
41
|
-
will_paginate (3.0.pre2)
|
42
|
-
|
43
|
-
PLATFORMS
|
44
|
-
ruby
|
45
|
-
|
46
|
-
DEPENDENCIES
|
47
|
-
bson (= 1.2.0)
|
48
|
-
bson_ext (= 1.2.0)
|
49
|
-
bundler (>= 1.0.0)
|
50
|
-
mocha
|
51
|
-
mongo (= 1.2.0)
|
52
|
-
mongoid (= 2.0.0.rc.6)
|
53
|
-
mongoid-eager-loading!
|
54
|
-
rspec (~> 2.0.0)
|
55
|
-
watchr
|