mongoid 4.0.0.alpha1 → 4.0.0.alpha2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +1 -1
- data/lib/config/locales/en.yml +4 -6
- data/lib/mongoid/attributes/processing.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -0
- data/lib/mongoid/contextual/map_reduce.rb +3 -1
- data/lib/mongoid/contextual/none.rb +90 -0
- data/lib/mongoid/criteria.rb +25 -0
- data/lib/mongoid/extensions/array.rb +1 -1
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/date.rb +1 -1
- data/lib/mongoid/extensions/date_time.rb +3 -3
- data/lib/mongoid/extensions/float.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/extensions/integer.rb +1 -1
- data/lib/mongoid/extensions/object.rb +3 -3
- data/lib/mongoid/extensions/object_id.rb +1 -1
- data/lib/mongoid/extensions/range.rb +1 -1
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/set.rb +1 -1
- data/lib/mongoid/extensions/string.rb +1 -1
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/time.rb +1 -1
- data/lib/mongoid/extensions/time_with_zone.rb +1 -1
- data/lib/mongoid/findable.rb +1 -0
- data/lib/mongoid/interceptable.rb +4 -2
- data/lib/mongoid/persistable.rb +4 -3
- data/lib/mongoid/relations/embedded/many.rb +1 -1
- data/lib/mongoid/relations/metadata.rb +8 -4
- data/lib/mongoid/relations/referenced/many.rb +1 -1
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/scopable.rb +2 -26
- data/lib/mongoid/validatable/uniqueness.rb +13 -0
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +0 -4
- data/spec/app/models/acolyte.rb +1 -1
- data/spec/app/models/address.rb +2 -2
- data/spec/app/models/appointment.rb +1 -1
- data/spec/app/models/audio.rb +1 -1
- data/spec/app/models/dog.rb +1 -1
- data/spec/app/models/event.rb +1 -1
- data/spec/app/models/house.rb +1 -1
- data/spec/app/models/message.rb +8 -0
- data/spec/app/models/person.rb +3 -2
- data/spec/app/models/player.rb +2 -2
- data/spec/app/models/post.rb +3 -2
- data/spec/app/models/preference.rb +1 -1
- data/spec/app/models/sound.rb +1 -1
- data/spec/app/models/symptom.rb +1 -1
- data/spec/app/models/tree.rb +2 -2
- data/spec/app/models/video.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +3 -3
- data/spec/mongoid/contextual/mongo_spec.rb +14 -14
- data/spec/mongoid/contextual/none_spec.rb +127 -0
- data/spec/mongoid/criteria/scopable_spec.rb +6 -6
- data/spec/mongoid/criteria_spec.rb +52 -96
- data/spec/mongoid/errors/invalid_scope_spec.rb +2 -2
- data/spec/mongoid/errors/mongoid_error_spec.rb +1 -1
- data/spec/mongoid/extensions/date_time_spec.rb +1 -1
- data/spec/mongoid/fields_spec.rb +6 -7
- data/spec/mongoid/findable_spec.rb +65 -0
- data/spec/mongoid/interceptable_spec.rb +11 -11
- data/spec/mongoid/persistable_spec.rb +4 -4
- data/spec/mongoid/relations/auto_save_spec.rb +1 -1
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +5 -5
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +1 -1
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +2 -2
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +14 -14
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +4 -4
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +10 -10
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +2 -2
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +1 -1
- data/spec/mongoid/relations/cascading/delete_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/destroy_spec.rb +4 -4
- data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/restrict_spec.rb +4 -4
- data/spec/mongoid/relations/eager_spec.rb +6 -6
- data/spec/mongoid/relations/embedded/many_spec.rb +36 -5
- data/spec/mongoid/relations/metadata_spec.rb +34 -15
- data/spec/mongoid/relations/referenced/many_spec.rb +19 -4
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +7 -7
- data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
- data/spec/mongoid/relations/targets/enumerable_spec.rb +2 -2
- data/spec/mongoid/relations/touchable_spec.rb +17 -0
- data/spec/mongoid/scopable_spec.rb +17 -40
- data/spec/mongoid/sessions/options_spec.rb +1 -1
- data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
- data/spec/mongoid/timestamps/updated/short_spec.rb +1 -1
- data/spec/mongoid/timestamps/updated_spec.rb +1 -1
- data/spec/mongoid/timestamps_spec.rb +2 -2
- data/spec/mongoid/validatable/associated_spec.rb +4 -4
- data/spec/mongoid/validatable/length_spec.rb +7 -7
- data/spec/mongoid/validatable/presence_spec.rb +6 -6
- data/spec/mongoid/validatable/uniqueness_spec.rb +44 -3
- data/spec/rails/mongoid_spec.rb +20 -20
- data/spec/spec_helper.rb +1 -0
- metadata +55 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a19035d46ca8c08250b25f7351b5b74a1fffd1f
|
|
4
|
+
data.tar.gz: 5d21abf409d5f12902c313678f5ced482ef5bf9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9a2567b69ffd592e74a45b345a52e2c15f1e0a049360313c847dc1b08e6ac081973d1cfb88dbae44db72f3eb3c1e4a68855916c0b70f1cae99fcc6cf8a60490
|
|
7
|
+
data.tar.gz: 93da6b0c3d2539ea4fd3126ac238019e16d5b6060de1bf81309ecaa40ab8cb5a023f7f558f2c4fbe5db65bf7f3f98b9fdb5da541dd5502f73d4d462333c6af37
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ For instructions on upgrading to newer versions, visit
|
|
|
7
7
|
|
|
8
8
|
### Major Changes (Backwards Incompatible)
|
|
9
9
|
|
|
10
|
+
* Scopes and default scopes must now all be defined within lambdas or procs.
|
|
11
|
+
|
|
12
|
+
* `skip_version_check` config option was removed.
|
|
13
|
+
|
|
10
14
|
* IdentityMap removed. (Arthur Neves)
|
|
11
15
|
|
|
12
16
|
* Eager load rework. Eager load now doesnt need the identity map to load
|
|
@@ -255,6 +259,15 @@ For instructions on upgrading to newer versions, visit
|
|
|
255
259
|
..
|
|
256
260
|
end
|
|
257
261
|
|
|
262
|
+
* \#3479 Map/reduce now respects criteria no timeout options if output is not
|
|
263
|
+
inline.
|
|
264
|
+
|
|
265
|
+
* \#3478 Criteria objects now have a #none method that will cause the criteria to
|
|
266
|
+
never hit the database and always have zero documents.
|
|
267
|
+
|
|
268
|
+
Band.none
|
|
269
|
+
Band.none.where(name: "Tool") # Always has zero documents.
|
|
270
|
+
|
|
258
271
|
* \#3319 Counters can now be reset from a document instance:
|
|
259
272
|
|
|
260
273
|
document.reset_counters(:relation)
|
|
@@ -291,8 +304,14 @@ For instructions on upgrading to newer versions, visit
|
|
|
291
304
|
|
|
292
305
|
### Resolved Issues
|
|
293
306
|
|
|
307
|
+
* \#3449 Touch needs to work for create and update. (Greggory Rothmeier)
|
|
308
|
+
|
|
309
|
+
* \#3432 Fixed mongoization of DateTime losing precision.
|
|
310
|
+
|
|
294
311
|
* \#3397 Fixed $ne matcher for embedded documents to match server behaviour.
|
|
295
312
|
|
|
313
|
+
* \#3352 Allow named scopes named "open" to work through 1-n relations.
|
|
314
|
+
|
|
296
315
|
* \#3348 Fixing compounded indexes having the same keys with
|
|
297
316
|
different directions. (Arthur Neves)
|
|
298
317
|
|
|
@@ -319,8 +338,19 @@ For instructions on upgrading to newer versions, visit
|
|
|
319
338
|
* \#3063 `Document#becomes` now properly sets base object on errors.
|
|
320
339
|
(Adam Ross Cohen)
|
|
321
340
|
|
|
341
|
+
* \#3019 Atomic operations will no longer attempt to persist if the document
|
|
342
|
+
is not persisted.
|
|
343
|
+
|
|
322
344
|
* \#2903 Removed unused string `to_a` extension.
|
|
323
345
|
|
|
346
|
+
## 3.1.7
|
|
347
|
+
|
|
348
|
+
### Resolved Issues
|
|
349
|
+
|
|
350
|
+
* \#3465 Fixed ambigous relation errors where inverse_of is set to nil.
|
|
351
|
+
|
|
352
|
+
* \#3414 Backkport skip and limit options on aggregation. (Wojciech Piekutowski)
|
|
353
|
+
|
|
324
354
|
## 3.1.6
|
|
325
355
|
|
|
326
356
|
### Resolved Issues
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Mongoid [](http://travis-ci.org/mongoid/mongoid) [](https://codeclimate.com/github/mongoid/mongoid) [](https://coveralls.io/r/mongoid/mongoid?branch=master)
|
|
1
|
+
Mongoid [](http://travis-ci.org/mongoid/mongoid) [](https://codeclimate.com/github/mongoid/mongoid) [](https://coveralls.io/r/mongoid/mongoid?branch=master) [](http://badge.fury.io/rb/mongoid)
|
|
2
2
|
========
|
|
3
3
|
|
|
4
4
|
Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
data/lib/config/locales/en.yml
CHANGED
|
@@ -119,6 +119,7 @@ en:
|
|
|
119
119
|
has the correct options.\n\n
|
|
120
120
|
Valid options are:\n
|
|
121
121
|
\_\_background: true|false\n
|
|
122
|
+
\_\_database: 'database_name'\n
|
|
122
123
|
\_\_drop_dups: true|false\n
|
|
123
124
|
\_\_name: 'index_name'\n
|
|
124
125
|
\_\_sparse: true|false\n
|
|
@@ -128,6 +129,7 @@ en:
|
|
|
128
129
|
\_\_bits: 26\n
|
|
129
130
|
\_\_bucket_size : 1\n
|
|
130
131
|
\_\_weights: { content: 1, title: 2 }\n
|
|
132
|
+
\_\_expire_after_seconds: number_of_seconds\n
|
|
131
133
|
Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n
|
|
132
134
|
Example:\n
|
|
133
135
|
\_\_class Band\n
|
|
@@ -156,15 +158,11 @@ en:
|
|
|
156
158
|
invalid_scope:
|
|
157
159
|
message: "Defining a scope of value %{value} on %{klass} is not
|
|
158
160
|
allowed."
|
|
159
|
-
summary: "Scopes in Mongoid must be
|
|
160
|
-
|
|
161
|
-
resolution: "Change the scope to be a criteria or proc wrapped
|
|
162
|
-
critera.\n\n
|
|
161
|
+
summary: "Scopes in Mongoid must be procs that wrap criteria objects."
|
|
162
|
+
resolution: "Change the scope to be a proc wrapped critera.\n\n
|
|
163
163
|
Example:\n
|
|
164
164
|
\_\_class Band\n
|
|
165
165
|
\_\_\_\_include Mongoid::Document\n
|
|
166
|
-
\_\_\_\_field :active, type: Boolean, default: true\n
|
|
167
|
-
\_\_\_\_scope :active, where(active: true)\n
|
|
168
166
|
\_\_\_\_scope :inactive, ->{ where(active: false) }\n
|
|
169
167
|
\_\_end\n\n"
|
|
170
168
|
invalid_storage_options:
|
|
@@ -19,7 +19,7 @@ module Mongoid
|
|
|
19
19
|
def process_attributes(attrs = nil)
|
|
20
20
|
attrs ||= {}
|
|
21
21
|
if !attrs.empty?
|
|
22
|
-
attrs = sanitize_for_mass_assignment(attrs)
|
|
22
|
+
attrs = sanitize_for_mass_assignment(attrs.to_hash)
|
|
23
23
|
attrs.each_pair do |key, value|
|
|
24
24
|
next if pending_attribute?(key, value)
|
|
25
25
|
process_attribute(key, value)
|
data/lib/mongoid/contextual.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
require "mongoid/contextual/queryable"
|
|
3
3
|
require "mongoid/contextual/mongo"
|
|
4
4
|
require "mongoid/contextual/memory"
|
|
5
|
+
require "mongoid/contextual/none"
|
|
5
6
|
|
|
6
7
|
module Mongoid
|
|
7
8
|
module Contextual
|
|
@@ -48,6 +49,7 @@ module Mongoid
|
|
|
48
49
|
#
|
|
49
50
|
# @since 3.0.0
|
|
50
51
|
def create_context
|
|
52
|
+
return None.new(self) if empty_and_chainable?
|
|
51
53
|
embedded ? Memory.new(self) : Mongo.new(self)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
@@ -268,7 +268,9 @@ module Mongoid
|
|
|
268
268
|
# @since 3.0.0
|
|
269
269
|
def documents
|
|
270
270
|
return results["results"] if results.has_key?("results")
|
|
271
|
-
session[output_collection].find
|
|
271
|
+
query = session[output_collection].find
|
|
272
|
+
query.no_timeout if criteria.options[:timeout] == false
|
|
273
|
+
query
|
|
272
274
|
end
|
|
273
275
|
|
|
274
276
|
# Get the collection that the map/reduce results were stored in.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module Mongoid
|
|
3
|
+
module Contextual
|
|
4
|
+
class None
|
|
5
|
+
include Enumerable
|
|
6
|
+
include Queryable
|
|
7
|
+
|
|
8
|
+
attr_reader :criteria, :klass
|
|
9
|
+
|
|
10
|
+
# Check if the context is equal to the other object.
|
|
11
|
+
#
|
|
12
|
+
# @example Check equality.
|
|
13
|
+
# context == []
|
|
14
|
+
#
|
|
15
|
+
# @param [ Array ] other The other array.
|
|
16
|
+
#
|
|
17
|
+
# @return [ true, false ] If the objects are equal.
|
|
18
|
+
#
|
|
19
|
+
# @since 4.0.0
|
|
20
|
+
def ==(other)
|
|
21
|
+
other.is_a?(None)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Iterate over the null context. There are no documents to iterate over
|
|
25
|
+
# in this case.
|
|
26
|
+
#
|
|
27
|
+
# @example Iterate over the context.
|
|
28
|
+
# context.each do |doc|
|
|
29
|
+
# puts doc.name
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
# @return [ Enumerator ] The enumerator.
|
|
33
|
+
#
|
|
34
|
+
# @since 4.0.0
|
|
35
|
+
def each
|
|
36
|
+
if block_given?
|
|
37
|
+
[].each { |doc| yield(doc) }
|
|
38
|
+
self
|
|
39
|
+
else
|
|
40
|
+
to_enum
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Do any documents exist for the context.
|
|
45
|
+
#
|
|
46
|
+
# @example Do any documents exist for the context.
|
|
47
|
+
# context.exists?
|
|
48
|
+
#
|
|
49
|
+
# @return [ true, false ] If the count is more than zero.
|
|
50
|
+
#
|
|
51
|
+
# @since 4.0.0
|
|
52
|
+
def exists?; false; end
|
|
53
|
+
|
|
54
|
+
# Create the new null context.
|
|
55
|
+
#
|
|
56
|
+
# @example Create the new context.
|
|
57
|
+
# Null.new(criteria)
|
|
58
|
+
#
|
|
59
|
+
# @param [ Criteria ] The criteria.
|
|
60
|
+
#
|
|
61
|
+
# @since 4.0.0
|
|
62
|
+
def initialize(criteria)
|
|
63
|
+
@criteria, @klass = criteria, criteria.klass
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Always returns nil.
|
|
67
|
+
#
|
|
68
|
+
# @example Get the last document.
|
|
69
|
+
# context.last
|
|
70
|
+
#
|
|
71
|
+
# @return [ nil ] Always nil.
|
|
72
|
+
#
|
|
73
|
+
# @since 4.0.0
|
|
74
|
+
def last; nil; end
|
|
75
|
+
|
|
76
|
+
# Always returns zero.
|
|
77
|
+
#
|
|
78
|
+
# @example Get the length of matching documents.
|
|
79
|
+
# context.length
|
|
80
|
+
#
|
|
81
|
+
# @return [ Integer ] Always zero.
|
|
82
|
+
#
|
|
83
|
+
# @since 4.0.0
|
|
84
|
+
def length
|
|
85
|
+
entries.length
|
|
86
|
+
end
|
|
87
|
+
alias :size :length
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
data/lib/mongoid/criteria.rb
CHANGED
|
@@ -297,6 +297,31 @@ module Mongoid
|
|
|
297
297
|
self
|
|
298
298
|
end
|
|
299
299
|
|
|
300
|
+
# Returns a criteria that will always contain zero results and never hits
|
|
301
|
+
# the database.
|
|
302
|
+
#
|
|
303
|
+
# @example Return a none criteria.
|
|
304
|
+
# criteria.none
|
|
305
|
+
#
|
|
306
|
+
# @return [ Criteria ] The none criteria.
|
|
307
|
+
#
|
|
308
|
+
# @since 4.0.0
|
|
309
|
+
def none
|
|
310
|
+
@none = true and self
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# Is the criteria an empty but chainable criteria?
|
|
314
|
+
#
|
|
315
|
+
# @example Is the criteria a none criteria?
|
|
316
|
+
# criteria.empty_and_chainable?
|
|
317
|
+
#
|
|
318
|
+
# @return [ true, false ] If the criteria is a none.
|
|
319
|
+
#
|
|
320
|
+
# @since 4.0.0
|
|
321
|
+
def empty_and_chainable?
|
|
322
|
+
!!@none
|
|
323
|
+
end
|
|
324
|
+
|
|
300
325
|
# Overriden to include _type in the fields.
|
|
301
326
|
#
|
|
302
327
|
# @example Limit the fields returned from the database.
|
|
@@ -12,9 +12,9 @@ module Mongoid
|
|
|
12
12
|
#
|
|
13
13
|
# @since 3.0.0
|
|
14
14
|
def __mongoize_time__
|
|
15
|
-
return
|
|
15
|
+
return to_time if utc? && Mongoid.use_utc?
|
|
16
16
|
if Mongoid.use_activesupport_time_zone?
|
|
17
|
-
in_time_zone(::Time.zone)
|
|
17
|
+
in_time_zone(::Time.zone).to_time
|
|
18
18
|
else
|
|
19
19
|
time = to_time
|
|
20
20
|
time.respond_to?(:getlocal) ? time.getlocal : time
|
|
@@ -70,4 +70,4 @@ module Mongoid
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
::DateTime.__send__(:include, Mongoid::Extensions::DateTime)
|
|
73
|
-
::DateTime.
|
|
73
|
+
::DateTime.extend(Mongoid::Extensions::DateTime::ClassMethods)
|
|
@@ -104,14 +104,14 @@ module Mongoid
|
|
|
104
104
|
send(name, *args) if name && respond_to?(name)
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
# Get the value for an instance variable or
|
|
107
|
+
# Get the value for an instance variable or false if it doesn't exist.
|
|
108
108
|
#
|
|
109
109
|
# @example Get the value for an instance var.
|
|
110
110
|
# document.ivar("person")
|
|
111
111
|
#
|
|
112
112
|
# @param [ String ] name The name of the variable.
|
|
113
113
|
#
|
|
114
|
-
# @return [ Object,
|
|
114
|
+
# @return [ Object, false ] The value or false.
|
|
115
115
|
#
|
|
116
116
|
# @since 2.0.0.rc.1
|
|
117
117
|
def ivar(name)
|
|
@@ -271,4 +271,4 @@ module Mongoid
|
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
::Object.__send__(:include, Mongoid::Extensions::Object)
|
|
274
|
-
::Object.
|
|
274
|
+
::Object.extend(Mongoid::Extensions::Object::ClassMethods)
|
|
@@ -53,4 +53,4 @@ module Mongoid
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
::ActiveSupport::TimeWithZone.__send__(:include, Mongoid::Extensions::TimeWithZone)
|
|
56
|
-
::ActiveSupport::TimeWithZone.
|
|
56
|
+
::ActiveSupport::TimeWithZone.extend(Mongoid::Extensions::TimeWithZone::ClassMethods)
|
data/lib/mongoid/findable.rb
CHANGED
|
@@ -252,10 +252,12 @@ module Mongoid
|
|
|
252
252
|
unless respond_to?(name)
|
|
253
253
|
chain = ActiveSupport::Callbacks::CallbackChain.new(name, {})
|
|
254
254
|
send("_#{kind}_callbacks").each do |callback|
|
|
255
|
-
chain.
|
|
255
|
+
chain.append(callback) if callback.kind == place
|
|
256
256
|
end
|
|
257
257
|
class_eval <<-EOM
|
|
258
|
-
def #{name}()
|
|
258
|
+
def #{name}()
|
|
259
|
+
#{chain.compile}
|
|
260
|
+
end
|
|
259
261
|
protected :#{name}
|
|
260
262
|
EOM
|
|
261
263
|
end
|
data/lib/mongoid/persistable.rb
CHANGED
|
@@ -142,7 +142,6 @@ module Mongoid
|
|
|
142
142
|
#
|
|
143
143
|
# @since 4.0.0
|
|
144
144
|
def prepare_atomic_operation
|
|
145
|
-
# @todo: Check if the document is persisted here.
|
|
146
145
|
operations = yield({})
|
|
147
146
|
persist_or_delay_atomic_operation(operations)
|
|
148
147
|
self
|
|
@@ -205,8 +204,10 @@ module Mongoid
|
|
|
205
204
|
#
|
|
206
205
|
# @since 4.0.0
|
|
207
206
|
def persist_atomic_operations(operations)
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
if persisted?
|
|
208
|
+
selector = atomic_selector
|
|
209
|
+
_root.collection.find(selector).update(positionally(selector, operations))
|
|
210
|
+
end
|
|
210
211
|
end
|
|
211
212
|
end
|
|
212
213
|
end
|