mongoid 1.2.10 → 1.2.11
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.
- data/VERSION +1 -1
- data/lib/mongoid/associations/has_many_related.rb +18 -1
- data/mongoid.gemspec +1 -1
- data/spec/integration/mongoid/associations_spec.rb +25 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.11
|
@@ -64,10 +64,27 @@ module Mongoid #:nodoc:
|
|
64
64
|
def initialize(document, options, target = nil)
|
65
65
|
@parent, @klass = document, options.klass
|
66
66
|
@foreign_key = options.foreign_key
|
67
|
-
@
|
67
|
+
@base = lambda { @klass.all(:conditions => { @foreign_key => document.id }) }
|
68
|
+
@target = target || @base.call
|
68
69
|
extends(options)
|
69
70
|
end
|
70
71
|
|
72
|
+
# Override the default behavior to allow the criteria to get reset on
|
73
|
+
# each call into the association.
|
74
|
+
#
|
75
|
+
# Example:
|
76
|
+
#
|
77
|
+
# person.posts.where(:title => "New")
|
78
|
+
# person.posts # resets the criteria
|
79
|
+
#
|
80
|
+
# Returns:
|
81
|
+
#
|
82
|
+
# A Criteria object or Array.
|
83
|
+
def method_missing(name, *args, &block)
|
84
|
+
@target = @base.call unless @target.is_a?(Array)
|
85
|
+
@target.send(name, *args, &block)
|
86
|
+
end
|
87
|
+
|
71
88
|
# Delegates to <<
|
72
89
|
def push(*objects)
|
73
90
|
self << objects
|
data/mongoid.gemspec
CHANGED
@@ -216,10 +216,33 @@ describe Mongoid::Associations do
|
|
216
216
|
|
217
217
|
end
|
218
218
|
|
219
|
-
|
219
|
+
context "calling criteria methods" do
|
220
220
|
|
221
|
-
|
221
|
+
before do
|
222
|
+
@post.title = "New Title"
|
223
|
+
@post.save
|
224
|
+
end
|
225
|
+
|
226
|
+
it "returns the proper object for the criteria" do
|
227
|
+
posts = @from_db.posts.where(:title => "New Title")
|
228
|
+
posts.size.should == 1
|
229
|
+
end
|
230
|
+
|
231
|
+
context "when calling with a new criteria" do
|
222
232
|
|
233
|
+
before do
|
234
|
+
@from_db.posts.create(:title => "Other Title")
|
235
|
+
end
|
236
|
+
|
237
|
+
it "does not retain the old criteria" do
|
238
|
+
@from_db.posts.where(:title => "New Title").size.should == 1
|
239
|
+
@from_db.posts.size.should == 2
|
240
|
+
@from_db.posts.where(:title => "Other Title").size.should == 1
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
223
246
|
end
|
224
247
|
|
225
248
|
context "nested embedded associations" do
|