mongoid 2.2.5 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,18 +3,712 @@
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.0 \[ In Development \] \[ Branch: master \]
6
+ ## 3.0.0 (branch: master)
7
+
8
+ ### New Features
9
+
10
+ * \#1741 Mongoid now provides a rake task to force remove indexes for
11
+ environments where Mongoid manages the index definitions and the
12
+ removal should be automated. (Hans Hasselberg)
13
+
14
+ rake db:force_remove_indexes
15
+ rake db:mongoid:force_remove_indexes
16
+
17
+ * \#1726 `Mongoid.load!` now accepts an optional second argument for the
18
+ environment to load. This takes precedence over any environment variable
19
+ that is set if provided.
20
+
21
+ Mongoid.load!("/path/to/mongoid.yml", :development)
22
+
23
+ * \#1724 Mongoid now supports regex fields.
24
+
25
+ class Rule
26
+ include Mongoid::Document
27
+ field :pattern, type: Regexp, default: /[^abc]/
28
+ end
29
+
30
+ * \#1714/\#1706 Added better logging on index creation. (Hans Hasselberg)
31
+
32
+ When an index is present on a root document model:
33
+
34
+ Creating indexes on: Model for: name, dob.
35
+
36
+ When an index is defined on an embedded model:
37
+
38
+ Index ignored on: Address, please define in the root model.
39
+
40
+ When no index is defined, nothing is logged, and if a bad index is
41
+ defined an error is raised.
42
+
43
+ * \#1710 For cases when you don't want Mongoid to auto-protect the id
44
+ and type attributes, you can set a configuration option to turn this
45
+ off.
46
+
47
+ Mongoid.protect_sensitive_fields = false
48
+
49
+ * \#1685 Belongs to relations now have build_ and create_ methods.
50
+
51
+ class Comment
52
+ include Mongoid::Document
53
+ belongs_to :user
54
+ end
55
+
56
+ comment = Comment.new
57
+ comment.build_user # Build a new user object
58
+ comment.create_user # Create a new user object
59
+
60
+ * \#1684 Raise a `Mongoid::Errors::InverseNotFound` when attempting to
61
+ set a child on a relation without the proper inverse_of definitions
62
+ due to Mongoid not being able to determine it.
63
+
64
+ class Lush
65
+ include Mongoid::Document
66
+ embeds_one :whiskey, class_name: "Drink"
67
+ end
68
+
69
+ class Drink
70
+ include Mongoid::Document
71
+ embedded_in :alcoholic, class_name: "Lush"
72
+ end
73
+
74
+ lush = Lush.new
75
+ lush.whiskey = Drink.new # raises an InverseNotFound error.
76
+
77
+ * \#1680 Polymorphic relations now use `*_type` keys in lookup queries.
78
+
79
+ class User
80
+ include Mongoid::Document
81
+ has_many :comments, as: :commentable
82
+ end
83
+
84
+ class Comment
85
+ include Mongoid::Document
86
+ belongs_to :commentable, polymorphic: true
87
+ end
88
+
89
+ user = User.find(id)
90
+ user.comments # Uses user.id and type "User" in the query.
91
+
92
+ * \#1677 Support for parent separable polymorphic relations to the same
93
+ parent class is now available. This only works if set from the parent
94
+ side in order to know which relation the children belong to.
95
+ (Douwe Maan)
96
+
97
+ class Face
98
+ include Mongoid::Document
99
+ has_one :left_eye, class_name: "Eye", as: :visible
100
+ has_one :right_eye, class_name: "Eye", as: :visible
101
+ end
102
+
103
+ class Eye
104
+ include Mongoid::Document
105
+ belongs_to :visible, polymorphic: true
106
+ end
107
+
108
+ face = Face.new
109
+ right_eye = Eye.new
110
+ left_eye = Eye.new
111
+ face.right_eye = right_eye
112
+ face.left_eye = left_eye
113
+ right_eye.visible = face # Will raise an error.
114
+
115
+ * \#1650 Objects that respond to \#to_criteria can now be merged into
116
+ existing criteria objects.
117
+
118
+ class Filter
119
+ def to_criteria
120
+ # return a Criteria object.
121
+ end
122
+ end
123
+
124
+ criteria = Person.where(title: "Sir")
125
+ criteria.merge(filter)
126
+
127
+ * \#1635 All exceptions now provide more comprehensive errors, including
128
+ the problem that occured, a detail summary of why it happened, and
129
+ potential resolutions. Example:
130
+
131
+ (Mongoid::Errors::DocumentNotFound)
132
+ Problem:
133
+ Document not found for class Town with
134
+ id(s) [BSON::ObjectId('4f35781b8ad54812e1000001')].
135
+ Summary:
136
+ When calling Town.find with an id or array of ids,
137
+ each parameter must match a document in the database
138
+ or this error will be raised.
139
+ Resolution:
140
+ Search for an id that is in the database or set the
141
+ Mongoid.raise_not_found_error configuration option to
142
+ false, which will cause a nil to be returned instead
143
+ of raising this error.
144
+
145
+ * \#1616 `Model.find_by` added which takes a hash of arugments to search
146
+ for in the database. If no single document is returned a DocumentNotFound
147
+ error is raised. (Piotr Jakubowski)
148
+
149
+ Band.find_by(name: "Depeche Mode")
150
+
151
+ * \#1477 Mongoid now automatically protects the id and type attributes
152
+ from mass assignment. You can override this (not recommended) by redefining
153
+ them as accessible.
154
+
155
+ class Band
156
+ include Mongoid::Document
157
+ attr_accessible :id, :_id, :_type
158
+ end
159
+
160
+ * \#1459 The identity map can be disabled now for specific code execution
161
+ by passing options to the unit of work.
162
+
163
+ Mongoid.unit_of_work(disable: :all) do
164
+ # Disables the identity map on all threads for the block.
165
+ end
166
+
167
+ Mongoid.unit_of_work(disable: :current) do
168
+ # Disables the identity map on the current thread for the block.
169
+ end
170
+
171
+ Mongoid.unit_of_work do
172
+ # Business as usual.
173
+ end
174
+
175
+ * \#1355 Associations now can have safety options provided to them on single
176
+ document persistence operations.
177
+
178
+ band.albums.safely.push(album)
179
+ band.albums.safely.create(name: "Smiths")
180
+
181
+ album.safely.create_producer(name: "Flood")
182
+
183
+ * \#1348 Eager loading is now supported on many-to-many relations.
184
+
185
+ * \#1292 Remove attribute now unsets the attribute when the document is
186
+ saved instead of setting to nil.
187
+
188
+ band = Band.find(id)
189
+ band.remove_attribute(:label) # Uses $unset when the document is saved.
190
+
191
+ * \#1212 Embedded documents can now be popped off a relation with persistence.
192
+
193
+ band.albums.pop # Pop 1 document and persist the removal.
194
+ band.albums.pop(3) # Pop 3 documents and persist the removal.
195
+
196
+ * \#1081 Mongoid indexes both id and type as a compound index when providing
197
+ `index: true` to a polymorphic belongs_to.
198
+
199
+ class Comment
200
+ include Mongoid::Document
201
+
202
+ # Indexes commentable_id and commentable_type as a compound index.
203
+ belongs_to :commentable, polymorphic: true, index: true
204
+ end
205
+
206
+ * \#1053 Raise a `Mongoid::Errors::UnknownAttribute` instead of no method
207
+ when attempting to set a field that is not defined and allow dynamic
208
+ fields is false. (Cyril Mougel)
209
+
210
+ Mongoid.allow_dynamic_fields = false
211
+
212
+ class Person
213
+ include Mongoid::Document
214
+ field :title, type: String
215
+ end
216
+
217
+ Person.new.age = 50 # raises the UnknownAttribute error.
218
+
219
+ * \#772 Fields can now be flagged as readonly, which will only let their
220
+ values be set when the document is new.
221
+
222
+ class Band
223
+ include Mongoid::Document
224
+ field :name, type: String
225
+ field :genre, type: String
226
+
227
+ attr_readonly :name, :genre
228
+ end
229
+
230
+ Readonly values are ignored when attempting to set them on persisted
231
+ documents, with the exception of update_attribute and remove_attribute,
232
+ where errors will get raised.
233
+
234
+ band = Band.create(name: "Depeche Mode")
235
+ band.update_attribute(:name, "Smiths") # Raises ReadonlyAttribute error.
236
+ band.remove_attribute(:name) # Raises ReadonlyAttribute error.
237
+
238
+
239
+ ### Major Changes
240
+
241
+ * `Model.defaults` no longer exists. You may get all defaults with a
242
+ combination of `Model.pre_processed_defaults` and
243
+ `Model.post_processed_defaults`
244
+
245
+ * `Model.identity` and `Model.key` have been removed. For custom ids,
246
+ users must now override the _id field.
247
+
248
+ When the default value is a proc, the default is applied *after* all
249
+ other attributes are set.
250
+
251
+ class Band
252
+ include Mongoid::Document
253
+ field :_id, type: String, default: ->{ name }
254
+ end
255
+
256
+ To have the default applied *before* other attributes, set `:pre_processed`
257
+ to true.
258
+
259
+ class Band
260
+ include Mongoid::Document
261
+ field :_id,
262
+ type: String,
263
+ pre_processed: true,
264
+ default: ->{ BSON::ObjectId.new.to_s }
265
+ end
266
+
267
+ * Custom application exceptions in various languages has been removed,
268
+ along with the `Mongoid.add_language` feature.
269
+
270
+ * Mongoid no longer supports 1.8 syntax. 1.9.x or other vms running in
271
+ 1.9 mode is now only supported.
272
+
273
+ * \#1734 When searching for documents via `Model.find` with multiple ids,
274
+ Mongoid will raise an error if not *all* ids are found, and tell you
275
+ what the missing ones were. Previously the error only got raised if
276
+ nothing was returned.
277
+
278
+ * \#1484 `Model#has_attribute?` now behaves the same as Active Record.
279
+
280
+ * \#1471 Mongoid no longer strips any level of precision off of times.
281
+
282
+ * \#1475 Active support's time zone is now used by default in time
283
+ serialization if it is defined.
284
+
285
+ * \#1342 `Model.find` and `model.relation.find` now only take a single or
286
+ multiple ids. The first/last/all with a conditions hash has been removed.
287
+
288
+ * \#1270 Relation macros have been changed to match their AR counterparts:
289
+ only :has_one, :has_many, :has_and_belongs_to_many, and :belongs_to
290
+ exist now.
291
+
292
+ * \#1268 `Model#new?` has been removed, developers must now always use
293
+ `Model#new_record?`.
294
+
295
+ * \#933 `:field.size` has been renamed to `:field.count` in criteria for
296
+ $size not to conflict with Symbol's size method.
297
+
298
+ ### Resolved Issues
299
+
300
+ * \#1718 Ensure consistency of #first/#last in relations - they now always
301
+ match first/last in the database, but opts for in memory first.
302
+
303
+ * \#1692/\#1376 `Model#updateattributes` and `Model#update_attributes!` now
304
+ accept assignment options. (Hans Hasselberg)
305
+
306
+ * \#1688/\#1207 Don't require namespacing when providing class name on
307
+ relation macros inside the namespace. (Hans Hasselberg)
308
+
309
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
310
+ \#matches. (Hans Hasselberg)
311
+
312
+ * \#1335 Don't add id sorting criteria to first/last is there is already
313
+ sorting options on the criteria.
314
+
315
+ * \#1135 DateTimes now properly get time zones on derserialization.
316
+
317
+ ## 2.4.5 (branch: 2.4.0-stable)
318
+
319
+ ### Resolved Issues
320
+
321
+ * \#1751 Mongoid's logger now responds to level for Ruby logging API
322
+ compatibility.
323
+
324
+ * \#1744/#1750 Sorting works now for localized fields in embedded documents
325
+ using the criteria API. (Hans Hasselberg)
326
+
327
+ * \#1746 Presence validation now shows which locales were empty for
328
+ localized fields. (Cyril Mougel)
329
+
330
+ * \#1727 Allow dot notation in embedded criteria to work on both embeds one
331
+ and embeds many. (Lyle Underwood)
332
+
333
+ * \#1723 Initialize callbacks should cascade through children without needing
334
+ to determine if the child is changed.
335
+
336
+ * \#1715 Serializable hashes are now consistent on inclusion of embedded
337
+ documents per or post save.
338
+
339
+ * \#1713 Fixing === checks when comparing a class with an instance of a
340
+ subclass.
341
+
342
+ * \#1495 Callbacks no longer get the 'super called outside of method` errors on
343
+ busted 1.8.7 rubies.
344
+
345
+ ## 2.4.4
346
+
347
+ ### Resolved Issues
348
+
349
+ * \#1705 Allow changing the order of many to many foreign keys.
350
+
351
+ * \#1703 Updated at is now versioned again. (Lucas Souza)
352
+
353
+ * \#1686 Set the base metadata on unbind as well as bind for belongs to
354
+ relations.
355
+
356
+ * \#1681 Attempt to create indexes for models without namespacing if the
357
+ namespace does not exist for the subdirectory.
358
+
359
+ * \#1676 Allow eager loading to work as a default scope.
360
+
361
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
362
+ \#matches. (Hans Hasselberg)
363
+
364
+ * \#1668 Ensure Mongoid logger exists before calling warn. (Rémy Coutable)
365
+
366
+ * \#1661 Ensure uniqueness validation works on cloned documents.
367
+
368
+ * \#1659 Clear delayed atomic sets when resetting the same embedded relation.
369
+
370
+ * \#1656/\#1657 Don't hit database for uniqueness validation if BOTH scope
371
+ and attribute hasn't changed. (priyaaank)
372
+
373
+ * \#1205/\#1642 When limiting fields returned from the database via
374
+ `Criteria#only` and `Criteria#without` and then subsequently saving
375
+ the document. Default values no longer override excluded fields.
376
+
377
+ ## 2.4.3
378
+
379
+ ### Resolved Issues
380
+
381
+ * \#1647 DateTime serialization when already in UTC does not convert to
382
+ local time.
383
+
384
+ * \#1641/\#1639 Mongoid.observer.disable :all now behaves as AR does.
385
+
386
+ * \#1640 Update consumers should be tied to the name of the collection
387
+ they persist to, not the name of the class.
388
+
389
+ * \#1637/\#1636 Scopes no longer modify parent class scopes when subclassing.
390
+ (Hans Hasselberg)
391
+
392
+ * \#1629 $all and $in criteria on embedded many relations now properly
393
+ handles regex searches and elements of varying length. (Douwe Maan)
394
+
395
+ * \#1623/\#1634 Default scopes no longer break Mongoid::Versioning.
396
+ (Hans Hasselberg)
397
+
398
+ * \#1605 Fix regression of rescue responses, Rails 3.2
399
+
400
+ ## 2.4.2
401
+
402
+ ### Resolved Issues
403
+
404
+ * \#1628 _type field can once again be included in serialization to json
405
+ or xml as a global option with `include_type_for_serialization`.
406
+ (Roman Shterenzon)
407
+
408
+ * \#1627 Validating format now works properly with localized fields.
409
+ (Douwe Maan)
410
+
411
+ * \#1617 Relation proxy methods now show up in Mongoid's list of
412
+ prohibited fields.
413
+
414
+ * \#1615 Allow a single configuration of host and port for all spec runs,
415
+ overridden by setting MONGOID_SPEC_HOST and MONGOID_SPEC_PORT env vars.
416
+
417
+ * \#1610 When versioning paranoid documents and max version is set, hard
418
+ delete old versions from the embedded relation.
419
+
420
+ * \#1609 Allow connection retry during cursor iteration as well as all other
421
+ operations.
422
+
423
+ * \#1608 Guard against no method errors when passing ids in nested attributes
424
+ and the documents do not exist.
425
+
426
+ * \#1605 Remove deprecation warning on rescue responses, Rails 3.2
427
+
428
+ * \#1602 Preserve structure of $and and $or queries when typecasting.
429
+
430
+ * \#1600 Uniqueness validation no longer errors when provided a relation.
431
+
432
+ * \#1599 Make sure enumerable targets yield to what is in memory first when
433
+ performing #each, not always the unloaded first.
434
+
435
+ * \#1597 Fix the ability to change the order of array fields with the same
436
+ elements.
437
+
438
+ * \#1590 Allow proper serialization of boolean values in criteria where the
439
+ field is nested inside an array.
440
+
441
+ ## 2.4.1
442
+
443
+ ### Resolved Issues
444
+
445
+ * \#1593 Arrays on embedded documents now properly atomically update when
446
+ modified from original version.
447
+
448
+ * \#1592 Don't swallow exceptions from index generation in the create_indexes
449
+ rake task.
450
+
451
+ * \#1589 Allow assignment of empty array to HABTM when no documents are yet
452
+ loaded into memory.
453
+
454
+ * \#1587 When a previous value for an array field was an explicit nil, it can
455
+ now be reset atomically with new values.
456
+
457
+ * \#1585 `Model#respond_to?` returns true now for the setter when allowing
458
+ dynamic fields.
459
+
460
+ * \#1582 Allow nil values to be set in arrays.
461
+
462
+ * \#1580 Allow arrays to be set to nil post save, and not just empty.
463
+
464
+ * \#1579 Don't call #to_a on individual set field elements in criterion.
465
+
466
+ * \#1576 Don't hit database on uniqueness validation if the field getting
467
+ validated has not changed.
468
+
469
+ * \#1571 Aliased fields get all the dirty attribute methods and all getters and
470
+ setters for both the original name and the alias. (Hans Hasselberg)
471
+
472
+ * \#1568 Fallback to development environment with warning when no env configured.
473
+
474
+ * \#1565 For fields and foreign keys with non-standard Ruby or database names,
475
+ use define_method instead of class_eval for creating the accessors and
476
+ dirty methods.
477
+
478
+ * \#1557 Internal strategy class no longer conflicts with models.
479
+
480
+ * \#1551 Parent documents now return `true` for `Model#changed?` if only child
481
+ (embedded) documents have changed.
482
+
483
+ * \#1547 Resetting persisted children from a parent save when new waits until post
484
+ callbacks, mirroring update functionality.
485
+
486
+ * \#1536 Eager loading now happens when calling `first` or `last` on a
487
+ criteria if inclusions are specified.
488
+
489
+ ## 2.4.0
7
490
 
8
491
  ### New Features
9
492
 
10
493
  * Ranges can now be passed to #where criteria to create a $gte/$lte query under the
11
494
  covers. `Person.where(dob: start_date...end_date)`
12
495
 
496
+ * Custom serializable fields can now override #selection to provide
497
+ customized serialization for criteria queries.
498
+
499
+ * \#1544 Internals use `Array.wrap` instead of `to_a` now where possible.
500
+
501
+ * \#1511 Presence validation now supports localized fields. (Tiago Rafael Godinho)
502
+
503
+ * \#1506 `Model.set` will now accept false and nil values. (Marten Veldthuis)
504
+
505
+ * \#1505 `Model.delete_all/destroy_all` now take either a :conditions hash or
506
+ the attributes directly.
507
+
508
+ * \#1504 `Model.recursively_embeds_many` now accepts a :cascade_callbacks
509
+ option. (Pavel Pravosud)
510
+
511
+ * \#1496 Mongoid now casts strings back to symbols for symbol fields that
512
+ get saved as strings by another application.
513
+
514
+ * \#1454, \#900 Associations now have an `after_build` callback that gets
515
+ executed after `.build` or `build_` methods are called.
516
+ (Jeffrey Jones, Ryan Townsend)
517
+
518
+ * \#1451 Ranges can now be any range value, not just numbers. (aupajo)
519
+
520
+ * \#1448 Localization is now used when sorting. (Hans Hasselberg)
521
+
522
+ * \#1422 Mongoid raises an error at yaml load if no environment is found.
523
+ (Tom Stuart)
524
+
525
+ * \#1413 $not support added to criteria symbol methods. (Marc Weil)
526
+
527
+ * \#1403 Added configuration option `scope_overwrite_exception` which defaults to
528
+ false for raising an error when defining a named scope with the same name of
529
+ an existing method. (Christoph Grabo)
530
+
531
+ * \#1388 `model.add_to_set` now supports adding multiple values and performs an
532
+ $addToSet with $each under the covers. (Christian Felder)
533
+
534
+ * \#1387 Added `Model#cache_key` for use in Rails caching. (Seivan Heidari)
535
+
536
+ * \#1380 Calling Model.find(id) will now properly convert to and from any type
537
+ based on the type of the _id field.
538
+
539
+ * \#1363 Added fallbacks and default support to localized fields, and added
540
+ ability to get and set all translations at once.
541
+
542
+ * \#1362 Aliased fields now properly typecast in criteria.
543
+
544
+ * \#1337 Array fields, including HABTM many foreign keys now have smarter dirty
545
+ checking and no longer perform a simple $set if the array has changed. If
546
+ items have only been added to the array, it performs a $pushAll. If items
547
+ have only been removed, it performs a $pullAll. If both additions and
548
+ removals have occurred it performs a $set to avoid conflicting mods.
549
+
13
550
  ### Resolved Issues
14
551
 
552
+ * Calling `Document#as_document` on a frozen document on Rubinius returns the
553
+ attributes instead of nil.
554
+
555
+ * \#1554 Split application of default values into proc/non-procs, where
556
+ non-procs get executed immediately during instantiation, and procs get
557
+ executed after all other values are set.
558
+
559
+ * \#1553 Combinations of adding and removing values from an array use a $set
560
+ on the current contents of the array, not the new values.
561
+
562
+ * \#1546 Dirty changes should be returned in a hash with indifferent access.
563
+
564
+ * \#1542 Eager loading now respects the options (ie skip, limit) provided to
565
+ the criteria when fetch the associations.
566
+
567
+ * \#1530 Don't duplicate added values to arrays via dirty tracking if the
568
+ array is a foreign key field.
569
+
570
+ * \#1529 Calling `unscoped` on relational associations now works properly.
571
+
572
+ * \#1524 Allow access to relations in overridden field setters by pre-setting
573
+ foreign key default values.
574
+
575
+ * \#1523 Allow disabling of observers via `disable`. (Jonas Schneider)
576
+
577
+ * \#1522 Fixed create indexes rake task for Rails 3.2. (Gray Manley)
578
+
579
+ * \#1517 Fix Mongoid documents to properly work with RSpec's stub_model.
580
+ (Tiago Rafael Godinho)
581
+
582
+ * \#1516 Don't duplicate relational many documents on bind.
583
+
584
+ * \#1515 Mongoid no longer attempts to serialize custom fields on complex
585
+ criteria by default.
586
+
587
+ * \#1503 Has many relation substitution now handles any kind of mix of existing
588
+ and new docs.
589
+
590
+ * \#1502 Nested attributes on embedded documents respects if the child is
591
+ paranoid.
592
+
593
+ * \#1497 Use provided message on failing uniqueness validation. (Justin Etheredge)
594
+
595
+ * \#1491 Return nil when no default set on localized fields. (Tiago Rafael Godinho)
596
+
597
+ * \#1483 Sending module includes at runtime which add new fields to a parent
598
+ document, also have the fields added to subclasses.
599
+
600
+ * \#1482 Applying new sorting options does not merge into previously
601
+ chained criteria. (Gerad Suyderhoud)
602
+
603
+ * \#1481 Fix invalid query when accessing many-to-many relations before
604
+ defaults are set.
605
+
606
+ * \#1480 Mongoid's internal serialized field types renamespaced to Internal in order
607
+ to not conflict with ruby core classes in custom serializable types.
608
+
609
+ * \#1479 Don't duplicate ids on many-to-many when using create or create!
610
+
611
+ * \#1469 When extract_id returns nil, get the document out of the identity map
612
+ by the criteria selector.
613
+
614
+ * \#1467 Defining a field named metadata now properly raises an invalid field
615
+ error.
616
+
617
+ * \#1463 Batch insert consumers are now scoped to collection to avoid persistence
618
+ of documents to other collections in callbacks going to the wrong place.
619
+
620
+ * \#1462 Assigning has many relations via nested attribtues `*_attributes=` does
621
+ not autosave the relation.
622
+
623
+ * \#1461 Fixed serialization of foreign key fields in complex criteria not to
624
+ escape the entire hash.
625
+
626
+ * \#1458 Versioning no longer skips fields that have been protected from mass
627
+ assignment.
628
+
629
+ * \#1455, \#1456 Calling destroy on any document now temporarily marks it as
630
+ flagged for destroy until the operation is complete. (Nader Akhnoukh)
631
+
632
+ * \#1453 `Model#to_key` should return a value when the document is destroyed.
633
+
634
+ * \#1449 New documents no longer get persisted when replaced on a has one as
635
+ a side effect. (jasonsydes)
636
+
637
+ * \#1439 embedded? should return true when relation defined as cyclic.
638
+
639
+ * \#1433 Polymorphic nested attributes for embedded and relational 1-1 now
640
+ update properly.
641
+
642
+ * \#1426 Frozen documents can now be cloned. (aagrawal2001)
643
+
644
+ * \#1382 Raise proper error when creating indexes via rake task if index
645
+ definition is incorrect. (Mathieu Ravaux)
646
+
647
+ * \#1381, \#1371 The identity map now functions properly with inherited
648
+ documents. (Paul Canavese)
649
+
650
+ * \#1370 Split concat on embedded arrays into its own method to handle the
651
+ batch processing due to after callback run execution issues.
652
+
653
+ * \#1366 Array and hash values now get deep copied for dirty tracking.
654
+
655
+ * \#1359 Provide ability to not have default scope applied to all named
656
+ scopes via using lambdas.
657
+
15
658
  * \#1333 Fixed errors with custom types that exist in namespaces. (Peter Gumeson)
16
659
 
17
- ## 2.3.4 \[ In Development \] \[ Branch: 2.3.0-stable \]
660
+ * \#1259 Default values are treated as dirty if they differ from the database
661
+ state.
662
+
663
+ * \#1255 Ensure embedded documents respect the defined default scope.
664
+
665
+ ## 2.3.4
666
+
667
+ * \#1445 Prevent duplicate documents in the loaded array on the target
668
+ enumerable for relational associations.
669
+
670
+ * \#1442 When using create_ methods for has one relations, the appropriate
671
+ destructive methods now get called when replacing an existing document.
672
+
673
+ * \#1431 Enumerable context should add to the loaded array post yield, so
674
+ that methods like #any? that short circuit based on the value of the block
675
+ dont falsely have extra documents.
676
+
677
+ * \#1418 Documents being loaded from the database for revision purposes
678
+ no longer get placed in the identity map.
679
+
680
+ * \#1399 Allow conversion of strings to integers in foreign keys where the
681
+ id is defined as an int.
682
+
683
+ * \#1397 Don't add default sorting criteria on first if they sort criteria
684
+ already exists.
685
+
686
+ * \#1394 Fix exists? to work when count is greater than 1. (Nick Hoffman)
687
+
688
+ * \#1392 Return 0 on aggregation functions where field is nonexistant.
689
+
690
+ * \#1391 Uniqueness validation now works properly on embedded documents that are
691
+ using primary key definitions.
692
+
693
+ * \#1390 When _type field is lower case class camelize before constantizing.
694
+
695
+ * \#1383 Fix cast on read for serializable fields that are subclassed.
696
+
697
+ * \#1357 Delayed atomic sets from update_attributes on embedded documents
698
+ multiple levels deep now properly persist.
699
+
700
+ * \#1326 Ensure base document on HABTM gets its keys saved after saving a newly
701
+ build child document.
702
+
703
+ * \#1301 Don't overwrite base metadata on embedded in relations if already set.
704
+
705
+ * \#1221 HABTM with inverse nil is allowed again on embedded documents.
706
+
707
+ * \#1208 Don't auto-persist child documents via the setter when setting from
708
+ an embedded_in.
709
+
710
+ * \#791 Root document updates its timestamps when only embedded documents have
711
+ changed.
18
712
 
19
713
  ## 2.3.3
20
714
 
@@ -211,6 +905,16 @@ For instructions on upgrading to newer versions, visit
211
905
  * Deleting versions created with `Mongoid::Versioning` no longer fires off
212
906
  dependent cascading on relations.
213
907
 
908
+ ## 2.2.6
909
+
910
+ * \#1751 Mongoid's logger now responds to level for Ruby logging API
911
+ compatibility.
912
+
913
+ ## 2.2.5
914
+
915
+ * This was a small patch release to address 2.2.x Heroku errors during asset
916
+ compilation.
917
+
214
918
  ## 2.2.4
215
919
 
216
920
  * \#1377 Fix aggregation functions to properly handle nil or indefined values.
@@ -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(klass)
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
@@ -20,101 +20,98 @@ module Mongoid #:nodoc
20
20
  end
21
21
  end
22
22
 
23
- module InstanceMethods #:nodoc:
24
-
25
- # Get all child +Documents+ to this +Document+, going n levels deep if
26
- # necessary. This is used when calling update persistence operations from
27
- # the root document, where changes in the entire tree need to be
28
- # determined. Note that persistence from the embedded documents will
29
- # always be preferred, since they are optimized calls... This operation
30
- # can get expensive in domains with large hierarchies.
31
- #
32
- # @example Get all the document's children.
33
- # person._children
34
- #
35
- # @return [ Array<Document> ] All child documents in the hierarchy.
36
- def _children
37
- @_children ||=
38
- [].tap do |children|
39
- relations.each_pair do |name, metadata|
40
- if metadata.embedded?
41
- child = send(name)
42
- child.to_a.each do |doc|
43
- children.push(doc)
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
- end
46
+ end
47
+ end
50
48
 
51
- # Determines if the document is a subclass of another document.
52
- #
53
- # @example Check if the document is a subclass
54
- # Square.new.hereditary?
55
- #
56
- # @return [ true, false ] True if hereditary, false if not.
57
- def hereditary?
58
- self.class.hereditary?
59
- end
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
- # Sets up a child/parent association. This is used for newly created
62
- # objects so they can be properly added to the graph.
63
- #
64
- # @example Set the parent document.
65
- # document.parentize(parent)
66
- #
67
- # @param [ Document ] document The parent document.
68
- #
69
- # @return [ Document ] The parent document.
70
- def parentize(document)
71
- self._parent = document
72
- end
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
- # Remove a child document from this parent. If an embeds one then set to
75
- # nil, otherwise remove from the embeds many.
76
- #
77
- # This is called from the +RemoveEmbedded+ persistence command.
78
- #
79
- # @example Remove the child.
80
- # document.remove_child(child)
81
- #
82
- # @param [ Document ] child The child (embedded) document to remove.
83
- #
84
- # @since 2.0.0.beta.1
85
- def remove_child(child)
86
- name = child.metadata.name
87
- child.embedded_one? ? remove_ivar(name) : send(name).delete_one(child)
88
- end
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
- # After children are persisted we can call this to move all their changes
91
- # and flag them as persisted in one call.
92
- #
93
- # @example Reset the children.
94
- # document.reset_persisted_children
95
- #
96
- # @return [ Array<Document> ] The children.
97
- #
98
- # @since 2.1.0
99
- def reset_persisted_children
100
- _children.each do |child|
101
- child.move_changes
102
- child.new_record = false
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
- # Return the root document in the object graph. If the current document
107
- # is the root object in the graph it will return self.
108
- #
109
- # @example Get the root document in the hierarchy.
110
- # document._root
111
- #
112
- # @return [ Document ] The root document in the hierarchy.
113
- def _root
114
- object = self
115
- while (object._parent) do object = object._parent; end
116
- object || self
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
@@ -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 :info, :debug, :error, :fatal, :unknown, :to => :logger, :allow_nil => true
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(root_class) ||
59
- Threaded.set_update_consumer(root_class, MODIFIERS[modifier].new)
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(root_class, nil)
64
+ Threaded.set_update_consumer(collection_name, nil)
65
65
  updater.execute(collection)
66
66
  end
67
67
  end
@@ -17,6 +17,7 @@ module Mongoid # :nodoc:
17
17
  # Backwards compatibility with Mongoid beta releases.
18
18
  delegate :klass, :to => :metadata
19
19
  delegate :bind_one, :unbind_one, :to => :binding
20
+ delegate :collection_name, :to => :base
20
21
 
21
22
  # Convenience for setting the target and the metadata properties since
22
23
  # all proxies will need to do this.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.2.5"
3
+ VERSION = "2.2.6"
4
4
  end
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.2.5
4
+ version: 2.2.6
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: 2011-12-19 00:00:00.000000000 Z
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: &70179270881220 !ruby/object:Gem::Requirement
16
+ requirement: &70168480357500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70179270881220
24
+ version_requirements: *70168480357500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70179270880520 !ruby/object:Gem::Requirement
27
+ requirement: &70168480357020 !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: *70179270880520
35
+ version_requirements: *70168480357020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70179270895860 !ruby/object:Gem::Requirement
38
+ requirement: &70168480356540 !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: *70179270895860
46
+ version_requirements: *70168480356540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70179270894860 !ruby/object:Gem::Requirement
49
+ requirement: &70168480356060 !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: *70179270894860
57
+ version_requirements: *70168480356060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70179270893840 !ruby/object:Gem::Requirement
60
+ requirement: &70168480355580 !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: *70179270893840
68
+ version_requirements: *70168480355580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70179270892380 !ruby/object:Gem::Requirement
71
+ requirement: &70168480355100 !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: *70179270892380
79
+ version_requirements: *70168480355100
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70179270890180 !ruby/object:Gem::Requirement
82
+ requirement: &70168480354620 !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: *70179270890180
90
+ version_requirements: *70168480354620
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: watchr
93
- requirement: &70179270889280 !ruby/object:Gem::Requirement
93
+ requirement: &70168480354140 !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: *70179270889280
101
+ version_requirements: *70168480354140
102
102
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
103
103
  in Ruby.
104
104
  email:
@@ -385,7 +385,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
385
385
  version: '0'
386
386
  segments:
387
387
  - 0
388
- hash: 4388686167094388523
388
+ hash: -2081146589811076586
389
389
  required_rubygems_version: !ruby/object:Gem::Requirement
390
390
  none: false
391
391
  requirements: