mongoid 3.0.3 → 3.0.4
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/CHANGELOG.md +21 -0
- data/lib/mongoid/contextual/memory.rb +34 -6
- data/lib/mongoid/contextual/mongo.rb +34 -4
- data/lib/mongoid/criteria.rb +14 -0
- data/lib/mongoid/criterion/scoping.rb +2 -2
- data/lib/mongoid/paranoia.rb +2 -0
- data/lib/mongoid/relations/constraint.rb +8 -2
- data/lib/mongoid/relations/referenced/many.rb +1 -1
- data/lib/mongoid/relations/synchronization.rb +2 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/mongoid.rb +5 -1
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,27 @@
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
4
4
|
[mongoid.org](http://mongoid.org/docs/upgrading.html).
|
5
5
|
|
6
|
+
## 3.0.4 (branch: 3.0.0-stable)
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#2280 Fix synchronization of many-to-many relations when an ordering default
|
11
|
+
scope exists on either side of the association.
|
12
|
+
|
13
|
+
* \#2278 `Criteria#update` now properly updates only the first matching document,
|
14
|
+
where `Criteria#update_all` will update all matching documents. (no flag vs multi).
|
15
|
+
|
16
|
+
* \#2274 When loading models, warn if error is raised but continue processing.
|
17
|
+
|
18
|
+
* \#2272 Don't wipe selectors or options when removing the default scope for
|
19
|
+
actual nil values. Must check if key exists as well.
|
20
|
+
|
21
|
+
* \#2266 Restored paranoid documents are no longer flagged as destroyed.
|
22
|
+
(Mario Uher)
|
23
|
+
|
24
|
+
* \#2263 Ensure casting of non object id foreign keys on many to many relations
|
25
|
+
happens in the initial set, not at validation time.
|
26
|
+
|
6
27
|
## 3.0.3
|
7
28
|
|
8
29
|
### Resolved Issues
|
@@ -239,29 +239,57 @@ module Mongoid
|
|
239
239
|
in_place_sort(values) and self
|
240
240
|
end
|
241
241
|
|
242
|
+
# Update the first matching document atomically.
|
243
|
+
#
|
244
|
+
# @example Update the matching document.
|
245
|
+
# context.update(name: "Smiths")
|
246
|
+
#
|
247
|
+
# @param [ Hash ] attributes The new attributes for the document.
|
248
|
+
#
|
249
|
+
# @return [ nil, false ] False if no attributes were provided.
|
250
|
+
#
|
251
|
+
# @since 3.0.0
|
252
|
+
def update(attributes = nil)
|
253
|
+
update_documents(attributes, [ first ])
|
254
|
+
end
|
255
|
+
|
242
256
|
# Update all the matching documents atomically.
|
243
257
|
#
|
244
258
|
# @example Update all the matching documents.
|
245
|
-
# context.
|
259
|
+
# context.update_all(name: "Smiths")
|
246
260
|
#
|
247
261
|
# @param [ Hash ] attributes The new attributes for each document.
|
248
262
|
#
|
249
263
|
# @return [ nil, false ] False if no attributes were provided.
|
250
264
|
#
|
251
265
|
# @since 3.0.0
|
252
|
-
def
|
266
|
+
def update_all(attributes = nil)
|
267
|
+
update_documents(attributes, entries)
|
268
|
+
end
|
269
|
+
|
270
|
+
private
|
271
|
+
|
272
|
+
# Update the provided documents with the attributes.
|
273
|
+
#
|
274
|
+
# @api private
|
275
|
+
#
|
276
|
+
# @example Update the documents.
|
277
|
+
# context.update_documents({}, doc)
|
278
|
+
#
|
279
|
+
# @param [ Hash ] attributes The attributes.
|
280
|
+
# @param [ Array<Document> ] docs The docs to update.
|
281
|
+
#
|
282
|
+
# @since 3.0.4
|
283
|
+
def update_documents(attributes, docs)
|
253
284
|
return false unless attributes
|
254
285
|
updates = {}
|
255
|
-
each do |doc|
|
286
|
+
docs.each do |doc|
|
256
287
|
@selector ||= root.atomic_selector
|
257
288
|
doc.write_attributes(attributes)
|
258
289
|
updates.merge!(doc.atomic_position => attributes)
|
259
290
|
end
|
260
291
|
collection.find(selector).update("$set" => updates)
|
261
292
|
end
|
262
|
-
alias :update_all :update
|
263
|
-
|
264
|
-
private
|
265
293
|
|
266
294
|
# Get the limiting value.
|
267
295
|
#
|
@@ -308,6 +308,20 @@ module Mongoid
|
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
311
|
+
# Update the first matching document atomically.
|
312
|
+
#
|
313
|
+
# @example Update the first matching document.
|
314
|
+
# context.update({ "$set" => { name: "Smiths" }})
|
315
|
+
#
|
316
|
+
# @param [ Hash ] attributes The new attributes for each document.
|
317
|
+
#
|
318
|
+
# @return [ nil, false ] False if no attributes were provided.
|
319
|
+
#
|
320
|
+
# @since 3.0.0
|
321
|
+
def update(attributes = nil)
|
322
|
+
update_documents(attributes)
|
323
|
+
end
|
324
|
+
|
311
325
|
# Update all the matching documents atomically.
|
312
326
|
#
|
313
327
|
# @example Update all the matching documents.
|
@@ -318,14 +332,30 @@ module Mongoid
|
|
318
332
|
# @return [ nil, false ] False if no attributes were provided.
|
319
333
|
#
|
320
334
|
# @since 3.0.0
|
321
|
-
def
|
322
|
-
|
323
|
-
query.update_all(attributes.__consolidate__)
|
335
|
+
def update_all(attributes = nil)
|
336
|
+
update_documents(attributes, :update_all)
|
324
337
|
end
|
325
|
-
alias :update_all :update
|
326
338
|
|
327
339
|
private
|
328
340
|
|
341
|
+
# Update the documents for the provided method.
|
342
|
+
#
|
343
|
+
# @api private
|
344
|
+
#
|
345
|
+
# @example Update the documents.
|
346
|
+
# context.update_documents(attrs)
|
347
|
+
#
|
348
|
+
# @param [ Hash ] attributes The updates.
|
349
|
+
# @param [ Symbol ] method The method to use.
|
350
|
+
#
|
351
|
+
# @return [ true, false ] If the update succeeded.
|
352
|
+
#
|
353
|
+
# @since 3.0.4
|
354
|
+
def update_documents(attributes, method = :update)
|
355
|
+
return false unless attributes
|
356
|
+
query.send(method, attributes.__consolidate__)
|
357
|
+
end
|
358
|
+
|
329
359
|
# Apply the field limitations.
|
330
360
|
#
|
331
361
|
# @api private
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -517,6 +517,20 @@ module Mongoid
|
|
517
517
|
super
|
518
518
|
end
|
519
519
|
|
520
|
+
# Get a version of this criteria without the options.
|
521
|
+
#
|
522
|
+
# @example Get the criteria without options.
|
523
|
+
# criteria.without_options
|
524
|
+
#
|
525
|
+
# @return [ Criteria ] The cloned criteria.
|
526
|
+
#
|
527
|
+
# @since 3.0.4
|
528
|
+
def without_options
|
529
|
+
crit = clone
|
530
|
+
crit.options.clear
|
531
|
+
crit
|
532
|
+
end
|
533
|
+
|
520
534
|
private
|
521
535
|
|
522
536
|
# Are documents in the query missing, and are we configured to raise an
|
@@ -32,10 +32,10 @@ module Mongoid
|
|
32
32
|
def remove_scoping(other)
|
33
33
|
if other
|
34
34
|
selector.reject! do |key, value|
|
35
|
-
other.selector[key] == value
|
35
|
+
other.selector.has_key?(key) && other.selector[key] == value
|
36
36
|
end
|
37
37
|
options.reject! do |key, value|
|
38
|
-
other.options[key] == value
|
38
|
+
other.options.has_key?(key) && other.options[key] == value
|
39
39
|
end
|
40
40
|
other.inclusions.each do |meta|
|
41
41
|
inclusions.delete_one(meta)
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -35,8 +35,14 @@ module Mongoid
|
|
35
35
|
# @since 2.0.0.rc.7
|
36
36
|
def convert(object)
|
37
37
|
return object if metadata.polymorphic?
|
38
|
-
klass = metadata.klass
|
39
|
-
klass.using_object_ids?
|
38
|
+
klass, field = metadata.klass, metadata.klass.fields["_id"]
|
39
|
+
if klass.using_object_ids?
|
40
|
+
Moped::BSON::ObjectId.mongoize(object)
|
41
|
+
elsif object.is_a?(::Array)
|
42
|
+
object.map!{ |obj| field.mongoize(obj) }
|
43
|
+
else
|
44
|
+
field.mongoize(object)
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
@@ -89,10 +89,10 @@ module Mongoid
|
|
89
89
|
end
|
90
90
|
|
91
91
|
unless adds.empty?
|
92
|
-
meta.criteria(adds, self.class).add_to_set(meta.inverse_foreign_key, id)
|
92
|
+
meta.criteria(adds, self.class).without_options.add_to_set(meta.inverse_foreign_key, id)
|
93
93
|
end
|
94
94
|
unless subs.empty?
|
95
|
-
meta.criteria(subs, self.class).pull(meta.inverse_foreign_key, id)
|
95
|
+
meta.criteria(subs, self.class).without_options.pull(meta.inverse_foreign_key, id)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
data/lib/mongoid/version.rb
CHANGED
data/lib/rails/mongoid.rb
CHANGED
@@ -118,7 +118,11 @@ module Rails
|
|
118
118
|
#
|
119
119
|
# @since 2.0.0.rc.3
|
120
120
|
def load_model(file)
|
121
|
-
|
121
|
+
begin
|
122
|
+
require_dependency(file)
|
123
|
+
rescue Exception => e
|
124
|
+
Logger.new($stdout).warn(e.message)
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
# Given the provided file name, determine the model and return the class.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -354,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
354
354
|
version: '0'
|
355
355
|
segments:
|
356
356
|
- 0
|
357
|
-
hash: -
|
357
|
+
hash: -1276565475413611308
|
358
358
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
359
359
|
none: false
|
360
360
|
requirements:
|