mongoid 2.3.4 → 2.3.5
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 +347 -2
- data/lib/mongoid/collection.rb +1 -1
- data/lib/mongoid/contexts/enumerable.rb +24 -0
- data/lib/mongoid/hierarchy.rb +84 -87
- data/lib/mongoid/logger.rb +7 -1
- data/lib/mongoid/relations/embedded/atomic.rb +3 -3
- data/lib/mongoid/relations/proxy.rb +1 -0
- data/lib/mongoid/version.rb +1 -1
- metadata +20 -20
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,356 @@
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
4
4
|
[mongoid.org](http://mongoid.org/docs/upgrading.html).
|
5
5
|
|
6
|
-
## 2.4.
|
6
|
+
## 2.4.5
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#1751 Mongoid's logger now responds to level for Ruby logging API
|
11
|
+
compatibility.
|
12
|
+
|
13
|
+
* \#1744/#1750 Sorting works now for localized fields in embedded documents
|
14
|
+
using the criteria API. (Hans Hasselberg)
|
15
|
+
|
16
|
+
* \#1746 Presence validation now shows which locales were empty for
|
17
|
+
localized fields. (Cyril Mougel)
|
18
|
+
|
19
|
+
* \#1727 Allow dot notation in embedded criteria to work on both embeds one
|
20
|
+
and embeds many. (Lyle Underwood)
|
21
|
+
|
22
|
+
* \#1723 Initialize callbacks should cascade through children without needing
|
23
|
+
to determine if the child is changed.
|
24
|
+
|
25
|
+
* \#1715 Serializable hashes are now consistent on inclusion of embedded
|
26
|
+
documents per or post save.
|
27
|
+
|
28
|
+
* \#1713 Fixing === checks when comparing a class with an instance of a
|
29
|
+
subclass.
|
30
|
+
|
31
|
+
* \#1495 Callbacks no longer get the 'super called outside of method` errors on
|
32
|
+
busted 1.8.7 rubies.
|
33
|
+
|
34
|
+
## 2.4.4
|
35
|
+
|
36
|
+
### Resolved Issues
|
37
|
+
|
38
|
+
* \#1705 Allow changing the order of many to many foreign keys.
|
39
|
+
|
40
|
+
* \#1703 Updated at is now versioned again. (Lucas Souza)
|
41
|
+
|
42
|
+
* \#1686 Set the base metadata on unbind as well as bind for belongs to
|
43
|
+
relations.
|
44
|
+
|
45
|
+
* \#1681 Attempt to create indexes for models without namespacing if the
|
46
|
+
namespace does not exist for the subdirectory.
|
47
|
+
|
48
|
+
* \#1676 Allow eager loading to work as a default scope.
|
49
|
+
|
50
|
+
* \#1665/#1672 Expand complex criteria in nested criteria selectors, like
|
51
|
+
#matches. (Hans Hasselberg)
|
52
|
+
|
53
|
+
* \#1668 Ensure Mongoid logger exists before calling warn. (Rémy Coutable)
|
54
|
+
|
55
|
+
* \#1661 Ensure uniqueness validation works on cloned documents.
|
56
|
+
|
57
|
+
* \#1659 Clear delayed atomic sets when resetting the same embedded relation.
|
58
|
+
|
59
|
+
* \#1656/#1657 Don't hit database for uniqueness validation if BOTH scope
|
60
|
+
and attribute hasn't changed. (priyaaank)
|
61
|
+
|
62
|
+
* \#1205/#1642 When limiting fields returned from the database via
|
63
|
+
`Criteria#only` and `Criteria#without` and then subsequently saving
|
64
|
+
the document. Default values no longer override excluded fields.
|
65
|
+
|
66
|
+
## 2.4.3
|
67
|
+
|
68
|
+
### Resolved Issues
|
69
|
+
|
70
|
+
* \#1647 DateTime serialization when already in UTC does not convert to
|
71
|
+
local time.
|
72
|
+
|
73
|
+
* \#1640 Update consumers should be tied to the name of the collection
|
74
|
+
they persist to, not the name of the class.
|
75
|
+
|
76
|
+
* \#1636 Scopes no longer modify parent class scopes when subclassing.
|
77
|
+
(Hans Hasselberg)
|
78
|
+
|
79
|
+
* \#1629 $all and $in criteria on embedded many relations now properly
|
80
|
+
handles regex searches and elements of varying length. (Douwe Maan)
|
81
|
+
|
82
|
+
* \#1623 Default scopes no longer break Mongoid::Versioning.
|
83
|
+
(Hans Hasselberg)
|
84
|
+
|
85
|
+
* \#1605 Fix regression of rescue responses, Rails 3.2
|
86
|
+
|
87
|
+
## 2.4.2
|
88
|
+
|
89
|
+
### Resolved Issues
|
90
|
+
|
91
|
+
* \#1627 Validating format now works properly with localized fields.
|
92
|
+
(Douwe Maan)
|
93
|
+
|
94
|
+
* \#1617 Relation proxy methods now show up in Mongoid's list of
|
95
|
+
prohibited fields.
|
96
|
+
|
97
|
+
* \#1615 Allow a single configuration of host and port for all spec runs,
|
98
|
+
overridden by setting MONGOID_SPEC_HOST and MONGOID_SPEC_PORT env vars.
|
99
|
+
|
100
|
+
* \#1610 When versioning paranoid documents and max version is set, hard
|
101
|
+
delete old versions from the embedded relation.
|
102
|
+
|
103
|
+
* \#1609 Allow connection retry during cursor iteration as well as all other
|
104
|
+
operations.
|
105
|
+
|
106
|
+
* \#1608 Guard against no method errors when passing ids in nested attributes
|
107
|
+
and the documents do not exist.
|
108
|
+
|
109
|
+
* \#1605 Remove deprecation warning on rescue responses, Rails 3.2
|
110
|
+
|
111
|
+
* \#1602 Preserve structure of $and and $or queries when typecasting.
|
112
|
+
|
113
|
+
* \#1600 Uniqueness validation no longer errors when provided a relation.
|
114
|
+
|
115
|
+
* \#1599 Make sure enumerable targets yield to what is in memory first when
|
116
|
+
performing #each, not always the unloaded first.
|
117
|
+
|
118
|
+
* \#1597 Fix the ability to change the order of array fields with the same
|
119
|
+
elements.
|
120
|
+
|
121
|
+
* \#1590 Allow proper serialization of boolean values in criteria where the
|
122
|
+
field is nested inside an array.
|
123
|
+
|
124
|
+
## 2.4.1
|
125
|
+
|
126
|
+
### Resolved Issues
|
127
|
+
|
128
|
+
* \#1593 Arrays on embedded documents now properly atomically update when
|
129
|
+
modified from original version.
|
130
|
+
|
131
|
+
* \#1592 Don't swallow exceptions from index generation in the create_indexes
|
132
|
+
rake task.
|
133
|
+
|
134
|
+
* \#1589 Allow assignment of empty array to HABTM when no documents are yet
|
135
|
+
loaded into memory.
|
136
|
+
|
137
|
+
* \#1587 When a previous value for an array field was an explicit nil, it can
|
138
|
+
now be reset atomically with new values.
|
139
|
+
|
140
|
+
* \#1585 `Model#respond_to?` returns true now for the setter when allowing
|
141
|
+
dynamic fields.
|
142
|
+
|
143
|
+
* \#1582 Allow nil values to be set in arrays.
|
144
|
+
|
145
|
+
* \#1580 Allow arrays to be set to nil post save, and not just empty.
|
146
|
+
|
147
|
+
* \#1579 Don't call #to_a on individual set field elements in criterion.
|
148
|
+
|
149
|
+
* \#1576 Don't hit database on uniqueness validation if the field getting
|
150
|
+
validated has not changed.
|
151
|
+
|
152
|
+
* \#1571 Aliased fields get all the dirty attribute methods and all getters and
|
153
|
+
setters for both the original name and the alias. (Hans Hasselberg)
|
154
|
+
|
155
|
+
* \#1568 Fallback to development environment with warning when no env configured.
|
156
|
+
|
157
|
+
* \#1565 For fields and foreign keys with non-standard Ruby or database names,
|
158
|
+
use define_method instead of class_eval for creating the accessors and
|
159
|
+
dirty methods.
|
160
|
+
|
161
|
+
* \#1557 Internal strategy class no longer conflicts with models.
|
162
|
+
|
163
|
+
* \#1551 Parent documents now return `true` for `Model#changed?` if only child
|
164
|
+
(embedded) documents have changed.
|
165
|
+
|
166
|
+
* \#1547 Resetting persisted children from a parent save when new waits until post
|
167
|
+
callbacks, mirroring update functionality.
|
168
|
+
|
169
|
+
* \#1536 Eager loading now happens when calling `first` or `last` on a
|
170
|
+
criteria if inclusions are specified.
|
171
|
+
|
172
|
+
## 2.4.0
|
173
|
+
|
174
|
+
### New Features
|
7
175
|
|
8
176
|
* Ranges can now be passed to #where criteria to create a $gte/$lte query under the
|
9
177
|
covers. `Person.where(dob: start_date...end_date)`
|
10
178
|
|
11
|
-
|
179
|
+
* Custom serializable fields can now override #selection to provide
|
180
|
+
customized serialization for criteria queries.
|
181
|
+
|
182
|
+
* \#1544 Internals use `Array.wrap` instead of `to_a` now where possible.
|
183
|
+
|
184
|
+
* \#1511 Presence validation now supports localized fields. (Tiago Rafael Godinho)
|
185
|
+
|
186
|
+
* \#1506 `Model.set` will now accept false and nil values. (Marten Veldthuis)
|
187
|
+
|
188
|
+
* \#1505 `Model.delete_all/destroy_all` now take either a :conditions hash or
|
189
|
+
the attributes directly.
|
190
|
+
|
191
|
+
* \#1504 `Model.recursively_embeds_many` now accepts a :cascade_callbacks
|
192
|
+
option. (Pavel Pravosud)
|
193
|
+
|
194
|
+
* \#1496 Mongoid now casts strings back to symbols for symbol fields that
|
195
|
+
get saved as strings by another application.
|
196
|
+
|
197
|
+
* \#1454, \#900 Associations now have an `after_build` callback that gets
|
198
|
+
executed after `.build` or `build_` methods are called.
|
199
|
+
(Jeffrey Jones, Ryan Townsend)
|
200
|
+
|
201
|
+
* \#1451 Ranges can now be any range value, not just numbers. (aupajo)
|
202
|
+
|
203
|
+
* \#1448 Localization is now used when sorting. (Hans Hasselberg)
|
204
|
+
|
205
|
+
* \#1422 Mongoid raises an error at yaml load if no environment is found.
|
206
|
+
(Tom Stuart)
|
207
|
+
|
208
|
+
* \#1413 $not support added to criteria symbol methods. (Marc Weil)
|
209
|
+
|
210
|
+
* \#1403 Added configuration option `scope_overwrite_exception` which defaults to
|
211
|
+
false for raising an error when defining a named scope with the same name of
|
212
|
+
an existing method. (Christoph Grabo)
|
213
|
+
|
214
|
+
* \#1388 `model.add_to_set` now supports adding multiple values and performs an
|
215
|
+
$addToSet with $each under the covers. (Christian Felder)
|
216
|
+
|
217
|
+
* \#1387 Added `Model#cache_key` for use in Rails caching. (Seivan Heidari)
|
218
|
+
|
219
|
+
* \#1380 Calling Model.find(id) will now properly convert to and from any type
|
220
|
+
based on the type of the _id field.
|
221
|
+
|
222
|
+
* \#1363 Added fallbacks and default support to localized fields, and added
|
223
|
+
ability to get and set all translations at once.
|
224
|
+
|
225
|
+
* \#1362 Aliased fields now properly typecast in criteria.
|
226
|
+
|
227
|
+
* \#1337 Array fields, including HABTM many foreign keys now have smarter dirty
|
228
|
+
checking and no longer perform a simple $set if the array has changed. If
|
229
|
+
items have only been added to the array, it performs a $pushAll. If items
|
230
|
+
have only been removed, it performs a $pullAll. If both additions and
|
231
|
+
removals have occurred it performs a $set to avoid conflicting mods.
|
232
|
+
|
233
|
+
### Resolved Issues
|
234
|
+
|
235
|
+
* Calling `Document#as_document` on a frozen document on Rubinius returns the
|
236
|
+
attributes instead of nil.
|
237
|
+
|
238
|
+
* \#1554 Split application of default values into proc/non-procs, where
|
239
|
+
non-procs get executed immediately during instantiation, and procs get
|
240
|
+
executed after all other values are set.
|
241
|
+
|
242
|
+
* \#1553 Combinations of adding and removing values from an array use a $set
|
243
|
+
on the current contents of the array, not the new values.
|
244
|
+
|
245
|
+
* \#1546 Dirty changes should be returned in a hash with indifferent access.
|
246
|
+
|
247
|
+
* \#1542 Eager loading now respects the options (ie skip, limit) provided to
|
248
|
+
the criteria when fetch the associations.
|
249
|
+
|
250
|
+
* \#1530 Don't duplicate added values to arrays via dirty tracking if the
|
251
|
+
array is a foreign key field.
|
252
|
+
|
253
|
+
* \#1529 Calling `unscoped` on relational associations now works properly.
|
254
|
+
|
255
|
+
* \#1524 Allow access to relations in overridden field setters by pre-setting
|
256
|
+
foreign key default values.
|
257
|
+
|
258
|
+
* \#1523 Allow disabling of observers via `disable`. (Jonas Schneider)
|
259
|
+
|
260
|
+
* \#1522 Fixed create indexes rake task for Rails 3.2. (Gray Manley)
|
261
|
+
|
262
|
+
* \#1517 Fix Mongoid documents to properly work with RSpec's stub_model.
|
263
|
+
(Tiago Rafael Godinho)
|
264
|
+
|
265
|
+
* \#1516 Don't duplicate relational many documents on bind.
|
266
|
+
|
267
|
+
* \#1515 Mongoid no longer attempts to serialize custom fields on complex
|
268
|
+
criteria by default.
|
269
|
+
|
270
|
+
* \#1503 Has many relation substitution now handles any kind of mix of existing
|
271
|
+
and new docs.
|
272
|
+
|
273
|
+
* \#1502 Nested attributes on embedded documents respects if the child is
|
274
|
+
paranoid.
|
275
|
+
|
276
|
+
* \#1497 Use provided message on failing uniqueness validation. (Justin Etheredge)
|
277
|
+
|
278
|
+
* \#1491 Return nil when no default set on localized fields. (Tiago Rafael Godinho)
|
279
|
+
|
280
|
+
* \#1483 Sending module includes at runtime which add new fields to a parent
|
281
|
+
document, also have the fields added to subclasses.
|
282
|
+
|
283
|
+
* \#1482 Applying new sorting options does not merge into previously
|
284
|
+
chained criteria. (Gerad Suyderhoud)
|
285
|
+
|
286
|
+
* \#1481 Fix invalid query when accessing many-to-many relations before
|
287
|
+
defaults are set.
|
288
|
+
|
289
|
+
* \#1480 Mongoid's internal serialized field types renamespaced to Internal in order
|
290
|
+
to not conflict with ruby core classes in custom serializable types.
|
291
|
+
|
292
|
+
* \#1479 Don't duplicate ids on many-to-many when using create or create!
|
293
|
+
|
294
|
+
* \#1469 When extract_id returns nil, get the document out of the identity map
|
295
|
+
by the criteria selector.
|
296
|
+
|
297
|
+
* \#1467 Defining a field named metadata now properly raises an invalid field
|
298
|
+
error.
|
299
|
+
|
300
|
+
* \#1463 Batch insert consumers are now scoped to collection to avoid persistence
|
301
|
+
of documents to other collections in callbacks going to the wrong place.
|
302
|
+
|
303
|
+
* \#1462 Assigning has many relations via nested attribtues `*_attributes=` does
|
304
|
+
not autosave the relation.
|
305
|
+
|
306
|
+
* \#1461 Fixed serialization of foreign key fields in complex criteria not to
|
307
|
+
escape the entire hash.
|
308
|
+
|
309
|
+
* \#1458 Versioning no longer skips fields that have been protected from mass
|
310
|
+
assignment.
|
311
|
+
|
312
|
+
* \#1455, \#1456 Calling destroy on any document now temporarily marks it as
|
313
|
+
flagged for destroy until the operation is complete. (Nader Akhnoukh)
|
314
|
+
|
315
|
+
* \#1453 `Model#to_key` should return a value when the document is destroyed.
|
316
|
+
|
317
|
+
* \#1449 New documents no longer get persisted when replaced on a has one as
|
318
|
+
a side effect. (jasonsydes)
|
319
|
+
|
320
|
+
* \#1439 embedded? should return true when relation defined as cyclic.
|
321
|
+
|
322
|
+
* \#1433 Polymorphic nested attributes for embedded and relational 1-1 now
|
323
|
+
update properly.
|
324
|
+
|
325
|
+
* \#1426 Frozen documents can now be cloned. (aagrawal2001)
|
326
|
+
|
327
|
+
* \#1382 Raise proper error when creating indexes via rake task if index
|
328
|
+
definition is incorrect. (Mathieu Ravaux)
|
329
|
+
|
330
|
+
* \#1381, \#1371 The identity map now functions properly with inherited
|
331
|
+
documents. (Paul Canavese)
|
332
|
+
|
333
|
+
* \#1370 Split concat on embedded arrays into its own method to handle the
|
334
|
+
batch processing due to after callback run execution issues.
|
335
|
+
|
336
|
+
* \#1366 Array and hash values now get deep copied for dirty tracking.
|
337
|
+
|
338
|
+
* \#1359 Provide ability to not have default scope applied to all named
|
339
|
+
scopes via using lambdas.
|
340
|
+
|
341
|
+
* \#1333 Fixed errors with custom types that exist in namespaces. (Peter Gumeson)
|
342
|
+
|
343
|
+
* \#1259 Default values are treated as dirty if they differ from the database
|
344
|
+
state.
|
345
|
+
|
346
|
+
* \#1255 Ensure embedded documents respect the defined default scope.
|
347
|
+
|
348
|
+
## 2.3.5
|
349
|
+
|
350
|
+
### Resolved Issues
|
351
|
+
|
352
|
+
* \#1751 Mongoid's logger now responds to level for Ruby logging API
|
353
|
+
compatibility.
|
354
|
+
|
355
|
+
## 2.3.4
|
12
356
|
|
13
357
|
* \#1445 Prevent duplicate documents in the loaded array on the target
|
14
358
|
enumerable for relational associations.
|
@@ -56,6 +400,7 @@ For instructions on upgrading to newer versions, visit
|
|
56
400
|
* \#791 Root document updates its timestamps when only embedded documents have
|
57
401
|
changed.
|
58
402
|
|
403
|
+
>>>>>>> 5f236a7... Mongoid's logger must respond to level. Fixes #1751.
|
59
404
|
## 2.3.3
|
60
405
|
|
61
406
|
### Resolved Issues
|
data/lib/mongoid/collection.rb
CHANGED
@@ -142,7 +142,7 @@ module Mongoid #:nodoc
|
|
142
142
|
#
|
143
143
|
# @since 2.0.0
|
144
144
|
def update(selector, document, options = {})
|
145
|
-
updater = Threaded.update_consumer(
|
145
|
+
updater = Threaded.update_consumer(name)
|
146
146
|
if updater
|
147
147
|
updater.consume(selector, document, options)
|
148
148
|
else
|
@@ -210,6 +210,18 @@ module Mongoid #:nodoc:
|
|
210
210
|
|
211
211
|
protected
|
212
212
|
|
213
|
+
# Get the root class collection name.
|
214
|
+
#
|
215
|
+
# @example Get the root class collection name.
|
216
|
+
# context.collection_name
|
217
|
+
#
|
218
|
+
# @return [ String ] The name of the collection.
|
219
|
+
#
|
220
|
+
# @since 2.4.3
|
221
|
+
def collection_name
|
222
|
+
root ? root.collection_name : nil
|
223
|
+
end
|
224
|
+
|
213
225
|
# Filters the documents against the criteria's selector
|
214
226
|
#
|
215
227
|
# @example Filter the documents.
|
@@ -251,10 +263,22 @@ module Mongoid #:nodoc:
|
|
251
263
|
documents
|
252
264
|
end
|
253
265
|
|
266
|
+
# Get the root document for the enumerable.
|
267
|
+
#
|
268
|
+
# @example Get the root document.
|
269
|
+
# context.root
|
270
|
+
#
|
271
|
+
# @return [ Document ] The root.
|
254
272
|
def root
|
255
273
|
@root ||= documents.first.try(:_root)
|
256
274
|
end
|
257
275
|
|
276
|
+
# Get the root class for the enumerable.
|
277
|
+
#
|
278
|
+
# @example Get the root class.
|
279
|
+
# context.root_class
|
280
|
+
#
|
281
|
+
# @return [ Class ] The root class.
|
258
282
|
def root_class
|
259
283
|
@root_class ||= root ? root.class : nil
|
260
284
|
end
|
data/lib/mongoid/hierarchy.rb
CHANGED
@@ -20,101 +20,98 @@ module Mongoid #:nodoc
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
children.concat(doc._children) unless metadata.versioned?
|
45
|
-
end if child
|
46
|
-
end
|
23
|
+
# Get all child +Documents+ to this +Document+, going n levels deep if
|
24
|
+
# necessary. This is used when calling update persistence operations from
|
25
|
+
# the root document, where changes in the entire tree need to be
|
26
|
+
# determined. Note that persistence from the embedded documents will
|
27
|
+
# always be preferred, since they are optimized calls... This operation
|
28
|
+
# can get expensive in domains with large hierarchies.
|
29
|
+
#
|
30
|
+
# @example Get all the document's children.
|
31
|
+
# person._children
|
32
|
+
#
|
33
|
+
# @return [ Array<Document> ] All child documents in the hierarchy.
|
34
|
+
def _children
|
35
|
+
@_children ||=
|
36
|
+
[].tap do |children|
|
37
|
+
relations.each_pair do |name, metadata|
|
38
|
+
if metadata.embedded?
|
39
|
+
child = send(name)
|
40
|
+
child.to_a.each do |doc|
|
41
|
+
children.push(doc)
|
42
|
+
children.concat(doc._children) unless metadata.versioned?
|
43
|
+
end if child
|
47
44
|
end
|
48
45
|
end
|
49
|
-
|
46
|
+
end
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
# Determines if the document is a subclass of another document.
|
50
|
+
#
|
51
|
+
# @example Check if the document is a subclass
|
52
|
+
# Square.new.hereditary?
|
53
|
+
#
|
54
|
+
# @return [ true, false ] True if hereditary, false if not.
|
55
|
+
def hereditary?
|
56
|
+
self.class.hereditary?
|
57
|
+
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
# Sets up a child/parent association. This is used for newly created
|
60
|
+
# objects so they can be properly added to the graph.
|
61
|
+
#
|
62
|
+
# @example Set the parent document.
|
63
|
+
# document.parentize(parent)
|
64
|
+
#
|
65
|
+
# @param [ Document ] document The parent document.
|
66
|
+
#
|
67
|
+
# @return [ Document ] The parent document.
|
68
|
+
def parentize(document)
|
69
|
+
self._parent = document
|
70
|
+
end
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
72
|
+
# Remove a child document from this parent. If an embeds one then set to
|
73
|
+
# nil, otherwise remove from the embeds many.
|
74
|
+
#
|
75
|
+
# This is called from the +RemoveEmbedded+ persistence command.
|
76
|
+
#
|
77
|
+
# @example Remove the child.
|
78
|
+
# document.remove_child(child)
|
79
|
+
#
|
80
|
+
# @param [ Document ] child The child (embedded) document to remove.
|
81
|
+
#
|
82
|
+
# @since 2.0.0.beta.1
|
83
|
+
def remove_child(child)
|
84
|
+
name = child.metadata.name
|
85
|
+
child.embedded_one? ? remove_ivar(name) : send(name).delete_one(child)
|
86
|
+
end
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
88
|
+
# After children are persisted we can call this to move all their changes
|
89
|
+
# and flag them as persisted in one call.
|
90
|
+
#
|
91
|
+
# @example Reset the children.
|
92
|
+
# document.reset_persisted_children
|
93
|
+
#
|
94
|
+
# @return [ Array<Document> ] The children.
|
95
|
+
#
|
96
|
+
# @since 2.1.0
|
97
|
+
def reset_persisted_children
|
98
|
+
_children.each do |child|
|
99
|
+
child.move_changes
|
100
|
+
child.new_record = false
|
104
101
|
end
|
102
|
+
end
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
104
|
+
# Return the root document in the object graph. If the current document
|
105
|
+
# is the root object in the graph it will return self.
|
106
|
+
#
|
107
|
+
# @example Get the root document in the hierarchy.
|
108
|
+
# document._root
|
109
|
+
#
|
110
|
+
# @return [ Document ] The root document in the hierarchy.
|
111
|
+
def _root
|
112
|
+
object = self
|
113
|
+
while (object._parent) do object = object._parent; end
|
114
|
+
object || self
|
118
115
|
end
|
119
116
|
end
|
120
117
|
end
|
data/lib/mongoid/logger.rb
CHANGED
@@ -4,7 +4,13 @@ module Mongoid #:nodoc:
|
|
4
4
|
# The Mongoid logger which wraps some other ruby compliant logger class.
|
5
5
|
class Logger
|
6
6
|
|
7
|
-
delegate
|
7
|
+
delegate \
|
8
|
+
:info,
|
9
|
+
:debug,
|
10
|
+
:error,
|
11
|
+
:fatal,
|
12
|
+
:level,
|
13
|
+
:unknown, :to => :logger, :allow_nil => true
|
8
14
|
|
9
15
|
# Emit a warning log message.
|
10
16
|
#
|
@@ -55,13 +55,13 @@ module Mongoid #:nodoc:
|
|
55
55
|
#
|
56
56
|
# @since 2.0.0
|
57
57
|
def atomically(modifier, &block)
|
58
|
-
updater = Threaded.update_consumer(
|
59
|
-
Threaded.set_update_consumer(
|
58
|
+
updater = Threaded.update_consumer(collection_name) ||
|
59
|
+
Threaded.set_update_consumer(collection_name, MODIFIERS[modifier].new)
|
60
60
|
count_executions do
|
61
61
|
block.call if block
|
62
62
|
end.tap do
|
63
63
|
if @executions.zero?
|
64
|
-
Threaded.set_update_consumer(
|
64
|
+
Threaded.set_update_consumer(collection_name, nil)
|
65
65
|
updater.execute(collection)
|
66
66
|
end
|
67
67
|
end
|
@@ -18,6 +18,7 @@ module Mongoid # :nodoc:
|
|
18
18
|
# Backwards compatibility with Mongoid beta releases.
|
19
19
|
delegate :klass, :to => :metadata
|
20
20
|
delegate :bind_one, :unbind_one, :to => :binding
|
21
|
+
delegate :collection_name, :to => :base
|
21
22
|
|
22
23
|
# Convenience for setting the target and the metadata properties since
|
23
24
|
# all proxies will need to do this.
|
data/lib/mongoid/version.rb
CHANGED
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: 2.3.
|
4
|
+
version: 2.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70140286687420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70140286687420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &70140286686940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.3.22
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70140286686940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mongo
|
38
|
-
requirement: &
|
38
|
+
requirement: &70140286686460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70140286686460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70140286685980 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.5.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70140286685980
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bson_ext
|
60
|
-
requirement: &
|
60
|
+
requirement: &70140286685500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.3'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70140286685500
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
|
-
requirement: &
|
71
|
+
requirement: &70140286685020 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.9.12
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70140286685020
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70140286684540 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '2.6'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70140286684540
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: watchr
|
93
|
-
requirement: &
|
93
|
+
requirement: &70140286684060 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0.6'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70140286684060
|
102
102
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
103
103
|
in Ruby.
|
104
104
|
email:
|
@@ -393,7 +393,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
393
393
|
version: '0'
|
394
394
|
segments:
|
395
395
|
- 0
|
396
|
-
hash:
|
396
|
+
hash: 2509135384989613869
|
397
397
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
398
398
|
none: false
|
399
399
|
requirements:
|