mongoid 2.4.10 → 3.0.0

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.
Files changed (356) hide show
  1. data/CHANGELOG.md +949 -10
  2. data/LICENSE +1 -1
  3. data/README.md +10 -11
  4. data/Rakefile +3 -17
  5. data/lib/config/locales/en.yml +455 -51
  6. data/lib/mongoid/atomic/modifiers.rb +2 -2
  7. data/lib/mongoid/atomic/paths/embedded/many.rb +6 -6
  8. data/lib/mongoid/atomic/paths/embedded/one.rb +5 -5
  9. data/lib/mongoid/atomic/paths/embedded.rb +4 -5
  10. data/lib/mongoid/atomic/paths/root.rb +4 -5
  11. data/lib/mongoid/atomic.rb +70 -16
  12. data/lib/mongoid/attributes/processing.rb +14 -10
  13. data/lib/mongoid/attributes/readonly.rb +56 -0
  14. data/lib/mongoid/attributes.rb +95 -32
  15. data/lib/mongoid/callbacks.rb +106 -43
  16. data/lib/mongoid/components.rb +12 -23
  17. data/lib/mongoid/config/environment.rb +7 -4
  18. data/lib/mongoid/config/inflections.rb +6 -0
  19. data/lib/mongoid/config/options.rb +1 -1
  20. data/lib/mongoid/config/validators/option.rb +25 -0
  21. data/lib/mongoid/config/validators/session.rb +140 -0
  22. data/lib/mongoid/config/validators.rb +3 -0
  23. data/lib/mongoid/config.rb +104 -225
  24. data/lib/mongoid/contextual/aggregable/memory.rb +109 -0
  25. data/lib/mongoid/contextual/aggregable/mongo.rb +181 -0
  26. data/lib/mongoid/contextual/atomic.rb +179 -0
  27. data/lib/mongoid/contextual/command.rb +43 -0
  28. data/lib/mongoid/contextual/find_and_modify.rb +68 -0
  29. data/lib/mongoid/contextual/map_reduce.rb +273 -0
  30. data/lib/mongoid/contextual/memory.rb +406 -0
  31. data/lib/mongoid/contextual/mongo.rb +662 -0
  32. data/lib/mongoid/contextual.rb +50 -0
  33. data/lib/mongoid/copyable.rb +7 -25
  34. data/lib/mongoid/criteria.rb +515 -245
  35. data/lib/mongoid/criterion/inspection.rb +14 -8
  36. data/lib/mongoid/criterion/scoping.rb +114 -44
  37. data/lib/mongoid/dirty.rb +152 -67
  38. data/lib/mongoid/document.rb +71 -52
  39. data/lib/mongoid/errors/ambiguous_relationship.rb +51 -0
  40. data/lib/mongoid/errors/callback.rb +5 -6
  41. data/lib/mongoid/errors/delete_restriction.rb +29 -0
  42. data/lib/mongoid/errors/document_not_found.rb +98 -17
  43. data/lib/mongoid/errors/eager_load.rb +3 -6
  44. data/lib/mongoid/errors/invalid_collection.rb +3 -3
  45. data/lib/mongoid/errors/invalid_config_option.rb +27 -0
  46. data/lib/mongoid/errors/invalid_database.rb +3 -3
  47. data/lib/mongoid/errors/invalid_field.rb +54 -8
  48. data/lib/mongoid/errors/invalid_field_option.rb +35 -0
  49. data/lib/mongoid/errors/invalid_find.rb +3 -3
  50. data/lib/mongoid/errors/invalid_index.rb +28 -0
  51. data/lib/mongoid/errors/invalid_options.rb +4 -4
  52. data/lib/mongoid/errors/invalid_scope.rb +24 -0
  53. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +38 -0
  54. data/lib/mongoid/errors/invalid_storage_options.rb +27 -0
  55. data/lib/mongoid/errors/invalid_time.rb +3 -6
  56. data/lib/mongoid/errors/inverse_not_found.rb +29 -0
  57. data/lib/mongoid/errors/mixed_relations.rb +4 -9
  58. data/lib/mongoid/errors/mixed_session_configuration.rb +28 -0
  59. data/lib/mongoid/errors/mongoid_error.rb +54 -3
  60. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +28 -0
  61. data/lib/mongoid/errors/no_default_session.rb +23 -0
  62. data/lib/mongoid/errors/no_environment.rb +3 -3
  63. data/lib/mongoid/errors/no_map_reduce_output.rb +24 -0
  64. data/lib/mongoid/errors/no_metadata.rb +21 -0
  65. data/lib/mongoid/errors/no_parent.rb +24 -0
  66. data/lib/mongoid/errors/no_session_config.rb +22 -0
  67. data/lib/mongoid/errors/no_session_database.rb +27 -0
  68. data/lib/mongoid/errors/no_session_hosts.rb +27 -0
  69. data/lib/mongoid/errors/no_sessions_config.rb +20 -0
  70. data/lib/mongoid/errors/readonly_attribute.rb +25 -0
  71. data/lib/mongoid/errors/scope_overwrite.rb +4 -4
  72. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +4 -4
  73. data/lib/mongoid/errors/unknown_attribute.rb +25 -0
  74. data/lib/mongoid/errors/unsaved_document.rb +4 -8
  75. data/lib/mongoid/errors/unsupported_javascript.rb +27 -0
  76. data/lib/mongoid/errors/unsupported_version.rb +4 -4
  77. data/lib/mongoid/errors/validations.rb +7 -6
  78. data/lib/mongoid/errors/versioning_not_on_root.rb +23 -0
  79. data/lib/mongoid/errors.rb +23 -1
  80. data/lib/mongoid/evolvable.rb +19 -0
  81. data/lib/mongoid/extensions/array.rb +164 -0
  82. data/lib/mongoid/extensions/big_decimal.rb +42 -0
  83. data/lib/mongoid/extensions/boolean.rb +24 -0
  84. data/lib/mongoid/extensions/date.rb +70 -0
  85. data/lib/mongoid/extensions/date_time.rb +73 -0
  86. data/lib/mongoid/extensions/false_class.rb +38 -0
  87. data/lib/mongoid/extensions/float.rb +56 -0
  88. data/lib/mongoid/extensions/hash.rb +123 -0
  89. data/lib/mongoid/extensions/integer.rb +66 -0
  90. data/lib/mongoid/extensions/module.rb +28 -0
  91. data/lib/mongoid/extensions/nil_class.rb +21 -0
  92. data/lib/mongoid/extensions/object.rb +238 -0
  93. data/lib/mongoid/extensions/object_id.rb +54 -0
  94. data/lib/mongoid/extensions/range.rb +79 -0
  95. data/lib/mongoid/extensions/regexp.rb +27 -0
  96. data/lib/mongoid/extensions/set.rb +55 -0
  97. data/lib/mongoid/extensions/string.rb +181 -0
  98. data/lib/mongoid/extensions/symbol.rb +54 -0
  99. data/lib/mongoid/extensions/time.rb +78 -0
  100. data/lib/mongoid/extensions/time_with_zone.rb +55 -0
  101. data/lib/mongoid/extensions/true_class.rb +38 -0
  102. data/lib/mongoid/extensions.rb +28 -76
  103. data/lib/mongoid/factory.rb +1 -1
  104. data/lib/mongoid/fields/foreign_key.rb +150 -0
  105. data/lib/mongoid/fields/localized.rb +73 -0
  106. data/lib/mongoid/fields/standard.rb +268 -0
  107. data/lib/mongoid/fields/validators/macro.rb +83 -0
  108. data/lib/mongoid/fields/validators.rb +2 -0
  109. data/lib/mongoid/fields.rb +142 -208
  110. data/lib/mongoid/finders.rb +45 -50
  111. data/lib/mongoid/hierarchy.rb +44 -15
  112. data/lib/mongoid/identity_map.rb +49 -21
  113. data/lib/mongoid/indexes/validators/options.rb +80 -0
  114. data/lib/mongoid/indexes.rb +66 -15
  115. data/lib/mongoid/inspection.rb +1 -1
  116. data/lib/mongoid/json.rb +2 -2
  117. data/lib/mongoid/loggable.rb +69 -0
  118. data/lib/mongoid/matchers/all.rb +7 -8
  119. data/lib/mongoid/matchers/and.rb +3 -3
  120. data/lib/mongoid/matchers/default.rb +6 -4
  121. data/lib/mongoid/matchers/exists.rb +2 -2
  122. data/lib/mongoid/matchers/gt.rb +2 -2
  123. data/lib/mongoid/matchers/gte.rb +2 -2
  124. data/lib/mongoid/matchers/in.rb +3 -7
  125. data/lib/mongoid/matchers/lt.rb +2 -2
  126. data/lib/mongoid/matchers/lte.rb +2 -2
  127. data/lib/mongoid/matchers/ne.rb +2 -2
  128. data/lib/mongoid/matchers/nin.rb +2 -2
  129. data/lib/mongoid/matchers/or.rb +2 -2
  130. data/lib/mongoid/matchers/size.rb +2 -2
  131. data/lib/mongoid/matchers/strategies.rb +3 -3
  132. data/lib/mongoid/matchers.rb +1 -1
  133. data/lib/mongoid/multi_parameter_attributes.rb +9 -11
  134. data/lib/mongoid/nested_attributes.rb +17 -9
  135. data/lib/mongoid/observer.rb +1 -2
  136. data/lib/mongoid/paranoia.rb +10 -44
  137. data/lib/mongoid/persistence/atomic/add_to_set.rb +5 -9
  138. data/lib/mongoid/persistence/atomic/bit.rb +5 -7
  139. data/lib/mongoid/persistence/atomic/inc.rb +5 -7
  140. data/lib/mongoid/persistence/atomic/operation.rb +45 -6
  141. data/lib/mongoid/persistence/atomic/pop.rb +5 -7
  142. data/lib/mongoid/persistence/atomic/pull.rb +5 -7
  143. data/lib/mongoid/persistence/atomic/pull_all.rb +5 -7
  144. data/lib/mongoid/persistence/atomic/push.rb +4 -10
  145. data/lib/mongoid/persistence/atomic/push_all.rb +4 -10
  146. data/lib/mongoid/persistence/atomic/rename.rb +6 -7
  147. data/lib/mongoid/persistence/atomic/sets.rb +5 -7
  148. data/lib/mongoid/persistence/atomic/unset.rb +4 -5
  149. data/lib/mongoid/persistence/atomic.rb +2 -2
  150. data/lib/mongoid/persistence/deletion.rb +2 -2
  151. data/lib/mongoid/persistence/insertion.rb +10 -16
  152. data/lib/mongoid/persistence/modification.rb +5 -9
  153. data/lib/mongoid/persistence/operations/embedded/insert.rb +7 -6
  154. data/lib/mongoid/persistence/operations/embedded/remove.rb +5 -5
  155. data/lib/mongoid/persistence/operations/insert.rb +4 -4
  156. data/lib/mongoid/persistence/operations/remove.rb +4 -4
  157. data/lib/mongoid/persistence/operations/update.rb +5 -5
  158. data/lib/mongoid/persistence/operations/upsert.rb +28 -0
  159. data/lib/mongoid/persistence/operations.rb +22 -19
  160. data/lib/mongoid/persistence/upsertion.rb +30 -0
  161. data/lib/mongoid/persistence.rb +94 -39
  162. data/lib/mongoid/railtie.rb +26 -11
  163. data/lib/mongoid/railties/database.rake +22 -108
  164. data/lib/mongoid/relations/accessors.rb +120 -20
  165. data/lib/mongoid/relations/auto_save.rb +59 -5
  166. data/lib/mongoid/relations/binding.rb +211 -2
  167. data/lib/mongoid/relations/bindings/embedded/in.rb +16 -22
  168. data/lib/mongoid/relations/bindings/embedded/many.rb +9 -50
  169. data/lib/mongoid/relations/bindings/embedded/one.rb +10 -16
  170. data/lib/mongoid/relations/bindings/referenced/in.rb +31 -57
  171. data/lib/mongoid/relations/bindings/referenced/many.rb +8 -20
  172. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +15 -19
  173. data/lib/mongoid/relations/bindings/referenced/one.rb +10 -24
  174. data/lib/mongoid/relations/builder.rb +4 -4
  175. data/lib/mongoid/relations/builders/embedded/in.rb +5 -5
  176. data/lib/mongoid/relations/builders/embedded/many.rb +12 -12
  177. data/lib/mongoid/relations/builders/embedded/one.rb +6 -6
  178. data/lib/mongoid/relations/builders/nested_attributes/many.rb +8 -8
  179. data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -5
  180. data/lib/mongoid/relations/builders/referenced/in.rb +4 -4
  181. data/lib/mongoid/relations/builders/referenced/many.rb +6 -6
  182. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +7 -5
  183. data/lib/mongoid/relations/builders/referenced/one.rb +5 -5
  184. data/lib/mongoid/relations/builders.rb +19 -16
  185. data/lib/mongoid/relations/cascading/delete.rb +3 -5
  186. data/lib/mongoid/relations/cascading/destroy.rb +3 -3
  187. data/lib/mongoid/relations/cascading/nullify.rb +3 -3
  188. data/lib/mongoid/relations/cascading/restrict.rb +37 -0
  189. data/lib/mongoid/relations/cascading.rb +10 -7
  190. data/lib/mongoid/relations/constraint.rb +4 -3
  191. data/lib/mongoid/relations/conversions.rb +6 -7
  192. data/lib/mongoid/relations/cyclic.rb +7 -7
  193. data/lib/mongoid/relations/embedded/batchable.rb +347 -0
  194. data/lib/mongoid/relations/embedded/in.rb +23 -12
  195. data/lib/mongoid/relations/embedded/many.rb +100 -161
  196. data/lib/mongoid/relations/embedded/one.rb +25 -14
  197. data/lib/mongoid/relations/macros.rb +105 -60
  198. data/lib/mongoid/relations/many.rb +93 -14
  199. data/lib/mongoid/relations/metadata.rb +277 -47
  200. data/lib/mongoid/relations/nested_builder.rb +4 -6
  201. data/lib/mongoid/relations/one.rb +2 -2
  202. data/lib/mongoid/relations/options.rb +2 -2
  203. data/lib/mongoid/relations/polymorphic.rb +9 -9
  204. data/lib/mongoid/relations/proxy.rb +62 -31
  205. data/lib/mongoid/relations/referenced/in.rb +40 -15
  206. data/lib/mongoid/relations/referenced/many.rb +162 -130
  207. data/lib/mongoid/relations/referenced/many_to_many.rb +104 -48
  208. data/lib/mongoid/relations/referenced/one.rb +34 -13
  209. data/lib/mongoid/relations/reflections.rb +3 -3
  210. data/lib/mongoid/relations/synchronization.rb +19 -23
  211. data/lib/mongoid/relations/targets/enumerable.rb +86 -57
  212. data/lib/mongoid/relations/touchable.rb +32 -0
  213. data/lib/mongoid/relations.rb +22 -6
  214. data/lib/mongoid/reloading.rb +12 -14
  215. data/lib/mongoid/scoping.rb +312 -0
  216. data/lib/mongoid/serialization.rb +94 -42
  217. data/lib/mongoid/sessions/factory.rb +108 -0
  218. data/lib/mongoid/sessions/mongo_uri.rb +93 -0
  219. data/lib/mongoid/sessions/validators/storage.rb +49 -0
  220. data/lib/mongoid/sessions/validators.rb +2 -0
  221. data/lib/mongoid/sessions.rb +383 -0
  222. data/lib/mongoid/sharding.rb +6 -6
  223. data/lib/mongoid/state.rb +6 -7
  224. data/lib/mongoid/threaded/lifecycle.rb +21 -21
  225. data/lib/mongoid/threaded/sessions.rb +0 -0
  226. data/lib/mongoid/threaded.rb +219 -59
  227. data/lib/mongoid/timestamps/created.rb +8 -4
  228. data/lib/mongoid/timestamps/timeless.rb +6 -4
  229. data/lib/mongoid/timestamps/updated.rb +4 -3
  230. data/lib/mongoid/timestamps.rb +1 -1
  231. data/lib/mongoid/unit_of_work.rb +61 -0
  232. data/lib/mongoid/validations/associated.rb +2 -2
  233. data/lib/mongoid/validations/format.rb +2 -2
  234. data/lib/mongoid/validations/presence.rb +34 -4
  235. data/lib/mongoid/validations/uniqueness.rb +11 -12
  236. data/lib/mongoid/validations.rb +28 -20
  237. data/lib/mongoid/version.rb +2 -2
  238. data/lib/mongoid/versioning.rb +25 -26
  239. data/lib/mongoid.rb +37 -37
  240. data/lib/rack/mongoid/middleware/identity_map.rb +3 -3
  241. data/lib/rails/generators/mongoid/config/config_generator.rb +1 -1
  242. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +65 -17
  243. data/lib/rails/generators/mongoid/model/model_generator.rb +7 -7
  244. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +2 -2
  245. data/lib/rails/generators/mongoid/observer/observer_generator.rb +4 -4
  246. data/lib/rails/generators/mongoid_generator.rb +5 -5
  247. data/lib/rails/mongoid.rb +73 -26
  248. metadata +103 -148
  249. data/lib/config/locales/bg.yml +0 -61
  250. data/lib/config/locales/de.yml +0 -61
  251. data/lib/config/locales/en-GB.yml +0 -64
  252. data/lib/config/locales/es.yml +0 -59
  253. data/lib/config/locales/fr.yml +0 -62
  254. data/lib/config/locales/hi.yml +0 -53
  255. data/lib/config/locales/hu.yml +0 -64
  256. data/lib/config/locales/id.yml +0 -62
  257. data/lib/config/locales/it.yml +0 -59
  258. data/lib/config/locales/ja.yml +0 -57
  259. data/lib/config/locales/kr.yml +0 -54
  260. data/lib/config/locales/nl.yml +0 -61
  261. data/lib/config/locales/pl.yml +0 -59
  262. data/lib/config/locales/pt-BR.yml +0 -60
  263. data/lib/config/locales/pt.yml +0 -60
  264. data/lib/config/locales/ro.yml +0 -66
  265. data/lib/config/locales/ru.yml +0 -61
  266. data/lib/config/locales/sv.yml +0 -60
  267. data/lib/config/locales/vi.yml +0 -62
  268. data/lib/config/locales/zh-CN.yml +0 -53
  269. data/lib/mongoid/collection.rb +0 -157
  270. data/lib/mongoid/collections/master.rb +0 -45
  271. data/lib/mongoid/collections/operations.rb +0 -44
  272. data/lib/mongoid/collections/retry.rb +0 -59
  273. data/lib/mongoid/collections.rb +0 -120
  274. data/lib/mongoid/config/database.rb +0 -181
  275. data/lib/mongoid/config/replset_database.rb +0 -80
  276. data/lib/mongoid/contexts/enumerable/sort.rb +0 -43
  277. data/lib/mongoid/contexts/enumerable.rb +0 -313
  278. data/lib/mongoid/contexts/mongo.rb +0 -487
  279. data/lib/mongoid/contexts.rb +0 -25
  280. data/lib/mongoid/criterion/builder.rb +0 -34
  281. data/lib/mongoid/criterion/complex.rb +0 -84
  282. data/lib/mongoid/criterion/creational.rb +0 -34
  283. data/lib/mongoid/criterion/exclusion.rb +0 -108
  284. data/lib/mongoid/criterion/inclusion.rb +0 -290
  285. data/lib/mongoid/criterion/optional.rb +0 -259
  286. data/lib/mongoid/criterion/selector.rb +0 -177
  287. data/lib/mongoid/cursor.rb +0 -88
  288. data/lib/mongoid/default_scope.rb +0 -36
  289. data/lib/mongoid/errors/invalid_type.rb +0 -25
  290. data/lib/mongoid/extensions/array/deep_copy.rb +0 -25
  291. data/lib/mongoid/extensions/array/deletion.rb +0 -29
  292. data/lib/mongoid/extensions/false_class/equality.rb +0 -26
  293. data/lib/mongoid/extensions/hash/criteria_helpers.rb +0 -47
  294. data/lib/mongoid/extensions/hash/deep_copy.rb +0 -25
  295. data/lib/mongoid/extensions/hash/scoping.rb +0 -25
  296. data/lib/mongoid/extensions/integer/checks.rb +0 -23
  297. data/lib/mongoid/extensions/nil/collectionization.rb +0 -23
  298. data/lib/mongoid/extensions/object/checks.rb +0 -29
  299. data/lib/mongoid/extensions/object/deep_copy.rb +0 -21
  300. data/lib/mongoid/extensions/object/reflections.rb +0 -48
  301. data/lib/mongoid/extensions/object/substitutable.rb +0 -15
  302. data/lib/mongoid/extensions/object/yoda.rb +0 -44
  303. data/lib/mongoid/extensions/object_id/conversions.rb +0 -60
  304. data/lib/mongoid/extensions/proc/scoping.rb +0 -25
  305. data/lib/mongoid/extensions/string/checks.rb +0 -36
  306. data/lib/mongoid/extensions/string/conversions.rb +0 -22
  307. data/lib/mongoid/extensions/string/inflections.rb +0 -118
  308. data/lib/mongoid/extensions/symbol/checks.rb +0 -23
  309. data/lib/mongoid/extensions/symbol/inflections.rb +0 -67
  310. data/lib/mongoid/extensions/true_class/equality.rb +0 -26
  311. data/lib/mongoid/extras.rb +0 -31
  312. data/lib/mongoid/fields/internal/array.rb +0 -76
  313. data/lib/mongoid/fields/internal/big_decimal.rb +0 -63
  314. data/lib/mongoid/fields/internal/bignum.rb +0 -10
  315. data/lib/mongoid/fields/internal/binary.rb +0 -11
  316. data/lib/mongoid/fields/internal/boolean.rb +0 -58
  317. data/lib/mongoid/fields/internal/date.rb +0 -51
  318. data/lib/mongoid/fields/internal/date_time.rb +0 -28
  319. data/lib/mongoid/fields/internal/false_class.rb +0 -10
  320. data/lib/mongoid/fields/internal/fixnum.rb +0 -10
  321. data/lib/mongoid/fields/internal/float.rb +0 -47
  322. data/lib/mongoid/fields/internal/foreign_keys/array.rb +0 -88
  323. data/lib/mongoid/fields/internal/foreign_keys/object.rb +0 -56
  324. data/lib/mongoid/fields/internal/hash.rb +0 -11
  325. data/lib/mongoid/fields/internal/integer.rb +0 -59
  326. data/lib/mongoid/fields/internal/localized.rb +0 -62
  327. data/lib/mongoid/fields/internal/nil_class.rb +0 -53
  328. data/lib/mongoid/fields/internal/object.rb +0 -11
  329. data/lib/mongoid/fields/internal/object_id.rb +0 -46
  330. data/lib/mongoid/fields/internal/range.rb +0 -61
  331. data/lib/mongoid/fields/internal/set.rb +0 -57
  332. data/lib/mongoid/fields/internal/string.rb +0 -42
  333. data/lib/mongoid/fields/internal/symbol.rb +0 -43
  334. data/lib/mongoid/fields/internal/time.rb +0 -23
  335. data/lib/mongoid/fields/internal/time_with_zone.rb +0 -23
  336. data/lib/mongoid/fields/internal/timekeeping.rb +0 -122
  337. data/lib/mongoid/fields/internal/true_class.rb +0 -10
  338. data/lib/mongoid/fields/mappings.rb +0 -42
  339. data/lib/mongoid/fields/serializable.rb +0 -270
  340. data/lib/mongoid/identity.rb +0 -92
  341. data/lib/mongoid/javascript/functions.yml +0 -63
  342. data/lib/mongoid/javascript.rb +0 -20
  343. data/lib/mongoid/keys.rb +0 -144
  344. data/lib/mongoid/logger.rb +0 -45
  345. data/lib/mongoid/multi_database.rb +0 -36
  346. data/lib/mongoid/named_scope.rb +0 -166
  347. data/lib/mongoid/relations/embedded/atomic/operation.rb +0 -63
  348. data/lib/mongoid/relations/embedded/atomic/pull.rb +0 -65
  349. data/lib/mongoid/relations/embedded/atomic/push_all.rb +0 -59
  350. data/lib/mongoid/relations/embedded/atomic/set.rb +0 -61
  351. data/lib/mongoid/relations/embedded/atomic/unset.rb +0 -41
  352. data/lib/mongoid/relations/embedded/atomic.rb +0 -89
  353. data/lib/mongoid/relations/referenced/batch/insert.rb +0 -57
  354. data/lib/mongoid/relations/referenced/batch.rb +0 -73
  355. data/lib/mongoid/safety.rb +0 -105
  356. data/lib/mongoid/scope.rb +0 -31
data/CHANGELOG.md CHANGED
@@ -3,10 +3,945 @@
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.11 (branch: 2.4.0-stable)
6
+ ## 3.0.0
7
+
8
+ ### New Features
9
+
10
+ * \#2151 When asking for metadata before persistence, Mongoid will now
11
+ raise a `Mongoid::Errors::NoMetadata` error if the metadata is not
12
+ present.
13
+
14
+ * \#2147 `Model#becomes` now copies over the embedded documents.
15
+
16
+ * A new callback has been introduced: `upsert`, which runs when calling
17
+ `document.upsert` since Mongoid does not know if the document is to be
18
+ treated as new or persisted. With this come the model callbacks:
19
+
20
+ before_upsert
21
+ after_upsert
22
+ around_upsert
23
+
24
+ * \#2080/\#2087 The database or session that Mongoid persists to can now be
25
+ overridden on a global level for cases where `Model#with` is not a viable
26
+ option.
27
+
28
+ Mongoid.override_database(:secondary)
29
+ Mongoid.override_session(:secondary)
30
+
31
+ Band.create(name: "Placebo") #=> Persists to secondary.
32
+ band.albums.create #=> Persists to secondary.
33
+
34
+ Note that this option is global and overrides for all models on the current
35
+ thread. It is the developer's responsibility to remember to set this back
36
+ to nil if you no longer want the override to happen.
37
+
38
+ Mongoid.override_database(nil)
39
+ Mongoid.override_session(nil)
40
+
41
+ * \#1989 Criteria `count`, `size` and `length` now behave as Active Record
42
+ with regards to database access.
43
+
44
+ `Criteria#count` will always hit the database to get the count.
45
+
46
+ `Criteria#length` and `Criteria#size` will hit the database once if the
47
+ criteria has not been loaded, and subsequent calls will return the
48
+ cached value.
49
+
50
+ If the criteria has been iterated over or loaded, `length` and `size`
51
+ will never hit the db.
52
+
53
+ * \#1976 Eager loading no longer produces queries when the base query returns
54
+ zero results.
55
+
56
+ * `Model.find_by` now accepts a block and will yield to the found document if
57
+ it is not nil.
58
+
59
+ Band.find_by(name: "Depeche Mode") do |band|
60
+ band.likes = 100
61
+ end
62
+
63
+ * \#1958/\#1798 Documents and `belongs_to` relations now support touch.
64
+
65
+ class Band
66
+ include Mongoid::Document
67
+ include Mongoid::Timestamps::Updated
68
+ belongs_to :label, touch: true
69
+ end
70
+
71
+ Update the document's updated_at timestamp to the current time. This
72
+ will also update any touchable relation's timestamp as well.
73
+
74
+ Band.first.touch
75
+
76
+ Update a specific time field along with the udpated_at.
77
+
78
+ Band.first.touch(:founded)
79
+
80
+ This fires no validations or callbacks.
81
+
82
+ * Mongoid now supports MongoDB's $findAndModify command.
83
+
84
+ Band.find_and_modify("$inc" => { likes: 1 })
85
+
86
+ Band.desc(:name).only(:name).find_and_modify(
87
+ { "$inc" => { likes: 1 }}, new: true
88
+ )
89
+
90
+ * \#1906 Mongoid will retrieve documents from the identity map when
91
+ providing multiple ids to find. (Hans Hasselberg)
92
+
93
+ * \#1903 Mongoid raises an error if provided a javascript expression
94
+ to a where clause on an embedded collection. (Sebastien Azimi)
95
+
96
+ * Aggregations now adhere to both a Mongoid API and their enumerable
97
+ counterparts where applicable.
98
+
99
+ Band.min(:likes)
100
+ Band.min do |a, b|
101
+ a.likes <=> b.likes
102
+ end
103
+
104
+ Band.max(:likes)
105
+ Band.max do |a, b|
106
+ a.likes <=> b.likes
107
+ end
108
+
109
+ Note that when providing a field name and no block, a single numeric
110
+ value will be returned, but when providing a block, a document will
111
+ be returned which has the min/max value. This is since Ruby's
112
+ Enumerable API dictates when providing a block, the matching element
113
+ is returned.
114
+
115
+ When providing a block, all documents will be loaded into memory.
116
+ When providing a symbol, the execution is handled via map/reduce on
117
+ the server.
118
+
119
+ * A kitchen sink aggregation method is now provided, to get everything in
120
+ in a single call for a field.
121
+
122
+ Band.aggregates(:likes)
123
+ # =>
124
+ # {
125
+ # "count" => 2.0,
126
+ # "max" => 1000.0,
127
+ # "min" => 500.0,
128
+ # "sum" => 1500.0,
129
+ # "avg" => 750.0
130
+ # }
131
+
132
+ * A DSL off the criteria API is now provided for map/reduce operations
133
+ as a convenience.
134
+
135
+ Band.where(name: "Tool").map_reduce(map, reduce).out(inline: 1)
136
+ Band.map_reduce(map, reduce).out(replace: "coll-name")
137
+ Band.map_reduce(map, reduce).out(inline: 1).finalize(finalize)
138
+
139
+ * Mongoid now uses Origin for its Criteria API. See the Origin repo
140
+ and API docs for the documentation.
141
+
142
+ * \#1861 Mongoid now raises an `AmbiguousRelationship` error when it
143
+ cannot determine the inverse of a relation and there are multiple
144
+ potential candidates. (Hans Hasselberg)
145
+
146
+ * You can now perform an explain directly from criteria.
147
+
148
+ Band.where(name: "Depeche Mode").explain
149
+
150
+ * \#1856 Push on one to many relations can now be chained.
151
+
152
+ band.albums.push(undertow).push(aenima)
153
+
154
+ * \#1842 MultiParameterAttributes now supported aliased fields.
155
+ (Anton Orel)
156
+
157
+ * \#1833 If an embedded document is attempted to be saved with no
158
+ parent defined, Mongoid now will raise a `Mongoid::Errors::NoParent`
159
+ exception.
160
+
161
+ * Added an ORM-agnostic way to get the field names
162
+
163
+ class Band
164
+ include Mongoid::Document
165
+ field :name, type: String
166
+ end
167
+
168
+ Band.attribute_names
169
+
170
+ * \#1831 `find_or_create_by` on relations now takes mass assignment
171
+ and type options. (Tatsuya Ono)
172
+
173
+ class Band
174
+ include Mongoid::Document
175
+ embeds_many :albums
176
+ end
177
+
178
+ band.albums.find_or_create_by({ name: "101" }, LP)
179
+
180
+ * \#1818 Add capability to choose the key where your `embeds_many` relation
181
+ is stores. (Cyril Mougel)
182
+
183
+ class User
184
+ include Mongoid::Document
185
+ field :name, type: String
186
+ embeds_many :prefs, class_name: "Preference", store_as: 'my_preferences'
187
+ end
188
+
189
+ user.prefs.build(value: "ok")
190
+ user.save
191
+ # document saves in MongoDB as:
192
+ # { "name" => "foo", "my_preferences" => [{ "value" => "ok" }]}
193
+
194
+ * \#1806 `Model.find_or_create_by` and `Model.find_or_initialize_by` can now
195
+ take documents as paramters for belongs_to relations.
196
+
197
+ person = Person.first
198
+ Game.find_or_create_by(person: person)
199
+
200
+ * \#1774 Relations now have a :restrict option for dependent relations
201
+ which will raise an error when attempting to delete a parent that
202
+ still has children on it. (Hans Hasselberg)
203
+
204
+ class Band
205
+ include Mongoid::Document
206
+ has_many :albums, dependent: :restrict
207
+ end
208
+
209
+ band = Band.first
210
+ band.albums << Albums.first
211
+ band.delete # Raises DeleteRestriction error.
212
+
213
+ * \#1764 Add method to check if field differs from the default value.
214
+
215
+ class Band
216
+ include Mongoid::Document
217
+ field :name, type: String, default: "New"
218
+ end
219
+
220
+ band = Band.first
221
+ band.name_changed_from_default?
222
+
223
+ * \#1759 Invalid fields error messages have been updated to show the
224
+ source and location of the original method. The new message is:
225
+
226
+ Problem:
227
+ Defining a field named 'crazy_method' is not allowed.
228
+ Summary:
229
+ Defining this field would override the method 'crazy_method',
230
+ which would cause issues with expectations around the original
231
+ method and cause extremely hard to debug issues.
232
+ The original method was defined in:
233
+ Object: MyModule
234
+ File: /path/to/my/module.rb
235
+ Line: 8
236
+ Resolution:
237
+ Use Mongoid.destructive_fields to see what names are
238
+ not allowed, and don't use these names. These include names
239
+ that also conflict with core Ruby methods on Object, Module,
240
+ Enumerable, or included gems that inject methods into these
241
+ or Mongoid internals.
242
+
243
+ * \#1753/#1649 A setter and getter for has_many relations to set it's
244
+ children is now provided. (Piotr Jakubowski)
245
+
246
+ class Album
247
+ include Mongoid::Document
248
+ has_many :engineers
249
+ end
250
+
251
+ class Engineer
252
+ include Mongoid::Document
253
+ belongs_to :album
254
+ end
255
+
256
+ album = Album.first
257
+ engineer = Engineer.first
258
+ album.engineer_ids = [ engineer.id ]
259
+ album.engineer_ids # Returns the ids of the engineers.
260
+
261
+ * \#1741 Mongoid now provides a rake task to force remove indexes for
262
+ environments where Mongoid manages the index definitions and the
263
+ removal should be automated. (Hans Hasselberg)
264
+
265
+ rake db:force_remove_indexes
266
+ rake db:mongoid:force_remove_indexes
267
+
268
+ * \#1726 `Mongoid.load!` now accepts an optional second argument for the
269
+ environment to load. This takes precedence over any environment variable
270
+ that is set if provided.
271
+
272
+ Mongoid.load!("/path/to/mongoid.yml", :development)
273
+
274
+ * \#1724 Mongoid now supports regex fields.
275
+
276
+ class Rule
277
+ include Mongoid::Document
278
+ field :pattern, type: Regexp, default: /[^abc]/
279
+ end
280
+
281
+ * \#1714/\#1706 Added better logging on index creation. (Hans Hasselberg)
282
+
283
+ When an index is present on a root document model:
284
+
285
+ Creating indexes on: Model for: name, dob.
286
+
287
+ When an index is defined on an embedded model:
288
+
289
+ Index ignored on: Address, please define in the root model.
290
+
291
+ When no index is defined, nothing is logged, and if a bad index is
292
+ defined an error is raised.
293
+
294
+ * \#1710 For cases when you don't want Mongoid to auto-protect the id
295
+ and type attributes, you can set a configuration option to turn this
296
+ off.
297
+
298
+ Mongoid.protect_sensitive_fields = false
299
+
300
+ * \#1685 Belongs to relations now have build_ and create_ methods.
301
+
302
+ class Comment
303
+ include Mongoid::Document
304
+ belongs_to :user
305
+ end
306
+
307
+ comment = Comment.new
308
+ comment.build_user # Build a new user object
309
+ comment.create_user # Create a new user object
310
+
311
+ * \#1684 Raise a `Mongoid::Errors::InverseNotFound` when attempting to
312
+ set a child on a relation without the proper inverse_of definitions
313
+ due to Mongoid not being able to determine it.
314
+
315
+ class Lush
316
+ include Mongoid::Document
317
+ embeds_one :whiskey, class_name: "Drink"
318
+ end
319
+
320
+ class Drink
321
+ include Mongoid::Document
322
+ embedded_in :alcoholic, class_name: "Lush"
323
+ end
324
+
325
+ lush = Lush.new
326
+ lush.whiskey = Drink.new # raises an InverseNotFound error.
327
+
328
+ * \#1680 Polymorphic relations now use `*_type` keys in lookup queries.
329
+
330
+ class User
331
+ include Mongoid::Document
332
+ has_many :comments, as: :commentable
333
+ end
334
+
335
+ class Comment
336
+ include Mongoid::Document
337
+ belongs_to :commentable, polymorphic: true
338
+ end
339
+
340
+ user = User.find(id)
341
+ user.comments # Uses user.id and type "User" in the query.
342
+
343
+ * \#1677 Support for parent separable polymorphic relations to the same
344
+ parent class is now available. This only works if set from the parent
345
+ side in order to know which relation the children belong to.
346
+ (Douwe Maan)
347
+
348
+ class Face
349
+ include Mongoid::Document
350
+ has_one :left_eye, class_name: "Eye", as: :visible
351
+ has_one :right_eye, class_name: "Eye", as: :visible
352
+ end
353
+
354
+ class Eye
355
+ include Mongoid::Document
356
+ belongs_to :visible, polymorphic: true
357
+ end
358
+
359
+ face = Face.new
360
+ right_eye = Eye.new
361
+ left_eye = Eye.new
362
+ face.right_eye = right_eye
363
+ face.left_eye = left_eye
364
+ right_eye.visible = face # Will raise an error.
365
+
366
+ * \#1650 Objects that respond to `to_criteria` can now be merged into
367
+ existing criteria objects.
368
+
369
+ class Filter
370
+ def to_criteria
371
+ # return a Criteria object.
372
+ end
373
+ end
374
+
375
+ criteria = Person.where(title: "Sir")
376
+ criteria.merge(filter)
377
+
378
+ * \#1635 All exceptions now provide more comprehensive errors, including
379
+ the problem that occured, a detail summary of why it happened, and
380
+ potential resolutions. Example:
381
+
382
+ (Mongoid::Errors::DocumentNotFound)
383
+ Problem:
384
+ Document not found for class Town with
385
+ id(s) [BSON::ObjectId('4f35781b8ad54812e1000001')].
386
+ Summary:
387
+ When calling Town.find with an id or array of ids,
388
+ each parameter must match a document in the database
389
+ or this error will be raised.
390
+ Resolution:
391
+ Search for an id that is in the database or set the
392
+ Mongoid.raise_not_found_error configuration option to
393
+ false, which will cause a nil to be returned instead
394
+ of raising this error.
395
+
396
+ * \#1616 `Model.find_by` added which takes a hash of arugments to search
397
+ for in the database. If no single document is returned a DocumentNotFound
398
+ error is raised. (Piotr Jakubowski)
399
+
400
+ Band.find_by(name: "Depeche Mode")
401
+
402
+ * \#1606 Mongoid now enables autosave, like Active Record, when adding
403
+ an accepts_nested_attributes_for to a relation.
404
+
405
+ class Band
406
+ include Mongoid::Document
407
+ has_many :albums
408
+ accepts_nested_attributes_for :albums # This enables the autosave.
409
+ end
410
+
411
+ * \#1477 Mongoid now automatically protects the id and type attributes
412
+ from mass assignment. You can override this (not recommended) by redefining
413
+ them as accessible.
414
+
415
+ class Band
416
+ include Mongoid::Document
417
+ attr_accessible :id, :_id, :_type
418
+ end
419
+
420
+ * \#1459 The identity map can be disabled now for specific code execution
421
+ by passing options to the unit of work.
422
+
423
+ Mongoid.unit_of_work(disable: :all) do
424
+ # Disables the identity map on all threads for the block.
425
+ end
426
+
427
+ Mongoid.unit_of_work(disable: :current) do
428
+ # Disables the identity map on the current thread for the block.
429
+ end
430
+
431
+ Mongoid.unit_of_work do
432
+ # Business as usual.
433
+ end
434
+
435
+ * \#1355 Associations now can have safety options provided to them on single
436
+ document persistence operations.
437
+
438
+ band.albums.with(safe: true).push(album)
439
+ band.albums.with(safe: true).create(name: "Smiths")
440
+
441
+ album.with(safe: true).create_producer(name: "Flood")
442
+
443
+ * \#1348 Eager loading is now supported on many-to-many relations.
444
+
445
+ * \#1292 Remove attribute now unsets the attribute when the document is
446
+ saved instead of setting to nil.
447
+
448
+ band = Band.find(id)
449
+ band.remove_attribute(:label) # Uses $unset when the document is saved.
450
+
451
+ * \#1291 Mongoid database sessions are now connected to lazily, and are
452
+ completely thread safe. If a new thread is created, then a new database
453
+ session will be created for it.
454
+
455
+ * \#1291 Mongoid now supports any number of database connections as defined in
456
+ the mongoid.yml. For example you could have a local single server db, a
457
+ multi availablity zone replica set, and a shard cluster all in the same
458
+ application environment. Mongoid can connect to any session at any point in
459
+ time.
460
+
461
+ * \#1291 Mongoid now allows you to persist to whatever database or collection
462
+ you like at runtime, on a per-query or persistence operation basis by using
463
+ `with`.
464
+
465
+ Band.with(collection: "artists").create(name: "Depeche Mode")
466
+ band.with(database: "secondary).save!
467
+ Band.with(collection: "artists").where(name: "Depeche Mode")
468
+
469
+ * \#1291 You can now configure on a per-model basis where it's documents are
470
+ stored with the new and improved `store_in` macro.
471
+
472
+ class Band
473
+ include Mongoid::Document
474
+ store_in collection: "artists", database: "secondary", session: "replica"
475
+ end
476
+
477
+ This can be overridden, of course, at runtime via the `with` method.
478
+
479
+ * \#1212 Embedded documents can now be popped off a relation with persistence.
480
+
481
+ band.albums.pop # Pop 1 document and persist the removal.
482
+ band.albums.pop(3) # Pop 3 documents and persist the removal.
483
+
484
+ * \#1188 Relations now have existence predicates for simplified checking if the
485
+ relation is blank or not. (Andy Morris)
486
+
487
+ class Band
488
+ include Mongoid::Document
489
+ embeds_many :albums
490
+ embeds_one :label
491
+ end
492
+
493
+ band = Band.new
494
+ band.albums?
495
+ band.has_albums?
496
+ band.label?
497
+ band.has_label?
498
+
499
+ * \#1188 1-1 relations now have an :autobuild option to indicate if the
500
+ relation should automatically be build with empty attributes upon access
501
+ where the relation currently does not exist. Works on embeds_one,
502
+ embedded_in, has_one, belongs_to. (Andy Morris)
503
+
504
+ class Band
505
+ include Mongoid::Document
506
+ has_one :label, autobuild: true
507
+ end
508
+
509
+ band = Band.new
510
+ band.label # Returns a new label with empty attributes.
511
+
512
+ When using existence checks, autobuilding will not execute.
513
+
514
+ band = Band.new
515
+ band.label? # Returns false, does not autobuild on a check.
516
+ band.has_label? # Returns false, does not autobuild on a check.
517
+
518
+ * \#1081 Mongoid indexes both id and type as a compound index when providing
519
+ `index: true` to a polymorphic belongs_to.
520
+
521
+ class Comment
522
+ include Mongoid::Document
523
+
524
+ # Indexes commentable_id and commentable_type as a compound index.
525
+ belongs_to :commentable, polymorphic: true, index: true
526
+ end
527
+
528
+ * \#1053 Raise a `Mongoid::Errors::UnknownAttribute` instead of no method
529
+ when attempting to set a field that is not defined and allow dynamic
530
+ fields is false. (Cyril Mougel)
531
+
532
+ Mongoid.allow_dynamic_fields = false
533
+
534
+ class Person
535
+ include Mongoid::Document
536
+ field :title, type: String
537
+ end
538
+
539
+ Person.new.age = 50 # raises the UnknownAttribute error.
540
+
541
+ * \#772 Fields can now be flagged as readonly, which will only let their
542
+ values be set when the document is new.
543
+
544
+ class Band
545
+ include Mongoid::Document
546
+ field :name, type: String
547
+ field :genre, type: String
548
+
549
+ attr_readonly :name, :genre
550
+ end
551
+
552
+ Readonly values are ignored when attempting to set them on persisted
553
+ documents, with the exception of update_attribute and remove_attribute,
554
+ where errors will get raised.
555
+
556
+ band = Band.create(name: "Depeche Mode")
557
+ band.update_attribute(:name, "Smiths") # Raises ReadonlyAttribute error.
558
+ band.remove_attribute(:name) # Raises ReadonlyAttribute error.
559
+
560
+
561
+ ### Major Changes (Backwards Incompatible)
562
+
563
+ * Polymorphic relations can not have ids other than object ids. This is
564
+ because Mongoid cannot properly figure out in an optimized way what the
565
+ various classes on the other side of the relation store their ids as, as
566
+ they could potentially all be different.
567
+
568
+ This was not allowed before, but nowhere was it explicitly stated.
569
+
570
+ * \#2039 Validating presence of a relation now checks both the relation and
571
+ the foreign key value.
572
+
573
+ * Indexing syntax has changed. The first parameter is now a hash of
574
+ name/direction pairs with an optional second hash parameter for
575
+ additional options.
576
+
577
+ Normal indexing with options, directions are either 1 or -1:
578
+
579
+ class Band
580
+ include Mongoid::Document
581
+ field :name, type: String
582
+
583
+ index({ name: 1 }, { unique: true, background: true })
584
+ end
585
+
586
+ Geospacial indexing needs "2d" as it's direction.
587
+
588
+ class Venue
589
+ include Mongoid::Document
590
+ field :location, type: Array
591
+
592
+ index location: "2d"
593
+ end
594
+
595
+ * Custom serializable fields have revamped. Your object no longer should
596
+ include `Mongoid::Fields::Serializable` - instead it only needs to
597
+ implement 3 methods: `#mongoize`, `.demongoize` and `.evolve`.
598
+
599
+ `#mongoize` is an instance method that transforms your object into
600
+ a mongo-friendly value.
601
+
602
+ `.demongoize` is a class method, that can take some data from mongo
603
+ and instantiate and object of your custom type.
604
+
605
+ `.evolve` is a class method, that can take any object, and
606
+ transform it for use in a `Mongoid::Criteria`.
607
+
608
+ An example of an implementation of this for `Range`:
609
+
610
+ class Range
611
+
612
+ def mongoize
613
+ { "min" => first, "max" => last }
614
+ end
615
+
616
+ class << self
617
+
618
+ def demongoize(object)
619
+ Range.new(object["min"], object["max"])
620
+ end
621
+
622
+ def evolve(object)
623
+ { "$gte" => object.first, "$lte" => object.last }
624
+ end
625
+ end
626
+ end
627
+
628
+ * `Document#changes` is no longer a hash with indifferent access.
629
+
630
+ * `after_initialize` callbacks no longer cascade to children if the option
631
+ is set.
632
+
633
+ * \#1865 `count` on the memory and mongo contexts now behave exactly the
634
+ same as Ruby's `count` on enumerable, and can take an object or a block.
635
+ This is optimized on the mongo context not to load everything in memory
636
+ with the exception of passing a block.
637
+
638
+ Band.where(name: "Tool").count
639
+ Band.where(name: "Tool").count(tool) # redundant.
640
+ Band.where(name: "Tool") do |doc|
641
+ doc.likes > 0
642
+ end
643
+
644
+ Note that although the signatures are the same for both the memory and
645
+ mongo contexts, it's recommended you only use the block syntax for the
646
+ memory context since the embedded documents are already loaded into
647
+ memory.
648
+
649
+ Also note that passing a boolean to take skip and limit into account
650
+ is no longer supported, as this is not necessarily a useful feature.
651
+
652
+ * The `autocreate_indexes` configuration option has been removed.
653
+
654
+ * `Model.defaults` no longer exists. You may get all defaults with a
655
+ combination of `Model.pre_processed_defaults` and
656
+ `Model.post_processed_defaults`.
657
+
658
+ Band.pre_processed_defaults
659
+ Band.post_processed_defaults
660
+
661
+ * `Model.identity` and `Model.key` have been removed. For custom ids,
662
+ users must now override the _id field.
663
+
664
+ When the default value is a proc, the default is applied *after* all
665
+ other attributes are set.
666
+
667
+ class Band
668
+ include Mongoid::Document
669
+ field :_id, type: String, default: ->{ name }
670
+ end
671
+
672
+ To have the default applied *before* other attributes, set `:pre_processed`
673
+ to true.
674
+
675
+ class Band
676
+ include Mongoid::Document
677
+ field :_id,
678
+ type: String,
679
+ pre_processed: true,
680
+ default: ->{ BSON::ObjectId.new.to_s }
681
+ end
682
+
683
+ * Custom application exceptions in various languages has been removed,
684
+ along with the `Mongoid.add_language` feature.
685
+
686
+ * Mongoid no longer supports 1.8. MRI 1.9.3 and higher, or JRuby 1.6 and
687
+ higher in 1.9 mode are only supported.
688
+
689
+ * \#1734 When searching for documents via `Model.find` with multiple ids,
690
+ Mongoid will raise an error if not *all* ids are found, and tell you
691
+ what the missing ones were. Previously the error only got raised if
692
+ nothing was returned.
693
+
694
+ * \#1675 Adding presence validation on a relation now enables autosave.
695
+ This is to ensure that when a new parent object is saved with a new
696
+ child and marked is valid, both are persisted to ensure a correct
697
+ state in the database.
698
+
699
+ * \#1491 Ensure empty translations returns an empty hash on access.
700
+
701
+ * \#1484 `Model#has_attribute?` now behaves the same as Active Record.
702
+
703
+ * \#1471 Mongoid no longer strips any level of precision off of times.
704
+
705
+ * \#1475 Active support's time zone is now used by default in time
706
+ serialization if it is defined.
707
+
708
+ * \#1342 `Model.find` and `model.relation.find` now only take a single or
709
+ multiple ids. The first/last/all with a conditions hash has been removed.
710
+
711
+ * \#1291 The mongoid.yml has been revamped completely, and upgrading
712
+ existing applications will greet you with some lovely Mongoid specific
713
+ configuration errors. You can re-generate a new mongoid.yml via the
714
+ existing rake task, which is commented to an insane degree to help you
715
+ with all the configuration possibilities.
716
+
717
+ * \#1291 The `persist_in_safe_mode` configuration option has been removed.
718
+ You must now tell a database session in the mongoid.yml whether or not
719
+ it should persist in safe mode by default.
720
+
721
+ production:
722
+ sessions:
723
+ default:
724
+ database: my_app_prod
725
+ hosts:
726
+ - db.app.com:27018
727
+ - db.app.com:27019
728
+ options:
729
+ consistency: :eventual
730
+ safe: true
731
+
732
+ * \#1291 `safely` and `unsafely` have been removed. Please now use `with`
733
+ to provide safe mode options at runtime.
734
+
735
+ Band.with(safe: true).create
736
+ band.with(safe: { w: 3 }).save!
737
+ Band.with(safe: false).create!
738
+
739
+ * \#1270 Relation macros have been changed to match their AR counterparts:
740
+ only :has_one, :has_many, :has_and_belongs_to_many, and :belongs_to
741
+ exist now.
742
+
743
+ * \#1268 `Model#new?` has been removed, developers must now always use
744
+ `Model#new_record?`.
745
+
746
+ * \#1182 A reload is no longer required to refresh a relation after setting
747
+ the value of the foreign key field for it. Note this behaves exactly as
748
+ Active Record.
749
+
750
+ If the id is set, but the document for it has not been persisted, accessing
751
+ the relation will return empty results.
752
+
753
+ If the id is set and it's document is persisted, accessing the relation
754
+ will return the document.
755
+
756
+ If the id is set, but the base document is not saved afterwards, then
757
+ reloading will return the document to it's original state.
758
+
759
+ * \#1093 Field serialization strategies have changed on Array, Hash, Integer
760
+ and Boolean to be more consistent and match AR where appropriate.
761
+
762
+ Serialization of arrays calls `Array.wrap(object)`
763
+ Serialization of hashes calls `Hash[object]` (to_hash on the object)
764
+ Serialization of integers always returns an int via `to_i`
765
+ Serialization of booleans defaults to false instead of nil.
766
+
767
+ * \#933 `:field.size` has been renamed to `:field.count` in criteria for
768
+ $size not to conflict with Symbol's size method.
769
+
770
+ * \#829/\#797 Mongoid scoping code has been completely rewritten, and now
771
+ matches the Active Record API. With this backwards incompatible change,
772
+ some methods have been removed or renamed.
773
+
774
+ Criteria#as_conditions and Criteria#fuse no longer exist.
775
+
776
+ Criteria#merge now only accepts another object that responds to
777
+ `to_criteria`.
778
+
779
+ Criteria#merge! now merges in another object without creating a new
780
+ criteria object.
781
+
782
+ Band.where(name: "Tool").merge!(criteria)
783
+
784
+ Named scopes and default scopes no longer take hashes as parameters.
785
+ From now on only criteria and procs wrapping criteria will be
786
+ accepted, and an error will be raised if the arguments are incorrect.
787
+
788
+ class Band
789
+ include Mongoid::Document
790
+
791
+ default_scope ->{ where(active: true) }
792
+ scope :inactive, where(active: false)
793
+ scope :invalid, where: { valid: false } # This will raise an error.
794
+ end
795
+
796
+ The 'named_scope' macro has been removed, from now on only use 'scope'.
797
+
798
+ Model.unscoped now accepts a block which will not allow default scoping
799
+ to be applied for any calls inside the block.
800
+
801
+ Band.unscoped do
802
+ Band.scoped.where(name: "Ministry")
803
+ end
804
+
805
+ Model.scoped now takes options that will be set directly on the criteria
806
+ options hash.
807
+
808
+ Band.scoped(skip: 10, limit: 20)
809
+
810
+ * \#463 `Document#upsert` is no longer aliased to `Document#save` and now
811
+ actually performs a proper MongoDB upsert command when called. If you
812
+ were using this method before and want the same behaviour, please switch
813
+ to `save`.
814
+
815
+ band = Band.new(name: "Tool")
816
+ band.upsert #=> Inserts the document in the database.
817
+ band.name = "Placebo"
818
+ band.upsert #=> Updates the existing document.
7
819
 
8
820
  ### Resolved Issues
9
821
 
822
+ * \#2166 `Criteria#from_map_or_db` strips type selection when eager loading
823
+ since it will check if the type is correct after.
824
+
825
+ * \#2129 Fixed sorting for all fields on embeds many relations.
826
+
827
+ * \#2124 Fixed default scope and deleted scope on paranoid documents.
828
+
829
+ * \#2122 Allow embedded documents to sort on boolean fields.
830
+
831
+ * \#2119 Allow `Criteria#update_all` to accept atomic ops and normal sets.
832
+
833
+ * \#2118 Don't strip any precision during `DateTime` -> `Time` conversions.
834
+
835
+ * \#2117 Ensure embeds one relations have callbacks run when using nested
836
+ attributes.
837
+
838
+ * \#2110 `Model#touch` now works properly on embedded documents.
839
+
840
+ * \#2100 Allow atomic operations to properly execute on paranoid documents
841
+ that have a deleted_at set.
842
+
843
+ * \#2089 Allow proper separation of mongoization and evolving with respect to
844
+ foreign keys.
845
+
846
+ * \#2088 Allow finds by string ids to pull from the identity map if the ids
847
+ are stored as object ids.
848
+
849
+ * \#2085 Allow demongoization of floats and ints to big decimals.
850
+
851
+ * \#2084 Don't cascade if metadata does not exist.
852
+
853
+ * \#2078 Calling `Model#clone` or `Model#dup` now properly sets attributes
854
+ as dirty.
855
+
856
+ * \#2070 Allow for updated_at to be overridden manually for new documents that
857
+ also have a created_at.
858
+
859
+ * \#2041 Don't hit the database multiple times on relation access after an
860
+ eager load returned zero documents.
861
+
862
+ * \#1997 Cascading callbacks should be able to halt the callback chain when
863
+ terminating.
864
+
865
+ * \#1972 `added`, `loaded`, and `unloaded` can now be valid scope names on a
866
+ document that is part of a 1-n relation.
867
+
868
+ * \#1952/#1950 `#all_in` behaviour on embedded documents now properly matches
869
+ root documents when passing an empty array. (Hans Hasselberg)
870
+
871
+ * \#1941/#1939 `Model.find_by` now returns nil if raise not found error is
872
+ set to false. (Hans Hasselberg)
873
+
874
+ * \#1859/#1860 `Model#remove_attribute` now properly unsets on embedded
875
+ documents. (Anton Onyshchenko)
876
+
877
+ * \#1852 Ensure no infinite recursion on cascading callbacks. (Ara Howard)
878
+
879
+ * \#1823 `Relation#includes?` now properly works with identity map enabled.
880
+
881
+ * \#1810 `Model#changed?` no longer returns true when hash and array fields
882
+ have only been accessed.
883
+
884
+ * \#1876/\#1782 Allow dot notation in embeds many criteria queries.
885
+ (Cyril Mougel)
886
+
887
+ * \#1745 Fixed batch clear to work within attribute setting.
888
+
889
+ * \#1718 Ensure consistency of #first/#last in relations - they now always
890
+ match first/last in the database, but opts for in memory first.
891
+
892
+ * \#1692/\#1376 `Model#updateattributes` and `Model#update_attributes!` now
893
+ accept assignment options. (Hans Hasselberg)
894
+
895
+ * \#1688/\#1207 Don't require namespacing when providing class name on
896
+ relation macros inside the namespace. (Hans Hasselberg)
897
+
898
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
899
+ \#matches. (Hans Hasselberg)
900
+
901
+ * \#1335 Don't add id sorting criteria to first/last is there is already
902
+ sorting options on the criteria.
903
+
904
+ * \#1321 Referenced many enumerable targets are now hash-backed, preventing
905
+ duplicates in a more efficient manner.
906
+
907
+ * \#1135 DateTimes now properly get time zones on deserialization.
908
+
909
+ * \#1031 Mongoid now serializes values in Array fields to their proper
910
+ Mongo-friendly values when possible.
911
+
912
+ * \#685 Attempting to use versioning with embedded documents will now
913
+ raise a proper error alerting the developer this is not allowed.
914
+
915
+ ## 2.4.12 (branch: 2.4.0-stable)
916
+
917
+ ### Resolved Issues
918
+
919
+ * \#2144 Uniqueness validation on paranoid documents now properly scopes.
920
+
921
+ * \#2127 Don't unbind parents of embedded documents mid nested
922
+ attributes deletion.
923
+
924
+ ## 2.4.11
925
+
926
+ ### Resolved Issues
927
+
928
+ * This release forces a cap on the mongo driver version at 1.6.2 due to
929
+ changes in the `Mongo::Connection.from_uri` API not allowing valid
930
+ connection options anymore.
931
+
932
+ * \#2040 Fixed bad interpolation for locale presence validation.
933
+
934
+ * \#2038 Allow inverse relations to be determined by foreign keys alone
935
+ if defined on both sides, not just an inverse_of declaration.
936
+
937
+ * \#2023 Allow serilialization of dynamic types that conflict with core
938
+ Ruby methods to still be serialized.
939
+
940
+ * \#2008 Presence validation should hit the db to check validity if the
941
+ relation in memory is blank.
942
+
943
+ * \#2006 Allow excluding only the _id field post execution of an #only call.
944
+
10
945
  ## 2.4.10
11
946
 
12
947
  ### Resolved Issues
@@ -23,8 +958,6 @@ For instructions on upgrading to newer versions, visit
23
958
  * \#1987 Don't double-insert documents into identity map when eager loading
24
959
  twice inside the unit of work.
25
960
 
26
- * \#1976 Don't execute eager load queries when base query is empty.
27
-
28
961
  * \#1953 Uniqueness validation now works on localized fields.
29
962
 
30
963
  * \#1936 Allow setting n levels deep embedded documents atomically without
@@ -66,7 +999,7 @@ For instructions on upgrading to newer versions, visit
66
999
  * \#1916/\#1913 Uniqueness validation no longer is affected by the default
67
1000
  scope. (Hans Hasselberg)
68
1001
 
69
- * \#1778 Ensure foreign keys are always set regardless of binding state.
1002
+ * \#1943 Ensure numericality validation works for big decimals.
70
1003
 
71
1004
  ## 2.4.8
72
1005
 
@@ -177,8 +1110,8 @@ For instructions on upgrading to newer versions, visit
177
1110
 
178
1111
  * \#1676 Allow eager loading to work as a default scope.
179
1112
 
180
- * \#1665/#1672 Expand complex criteria in nested criteria selectors, like
181
- #matches. (Hans Hasselberg)
1113
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
1114
+ \#matches. (Hans Hasselberg)
182
1115
 
183
1116
  * \#1668 Ensure Mongoid logger exists before calling warn. (Rémy Coutable)
184
1117
 
@@ -186,10 +1119,10 @@ For instructions on upgrading to newer versions, visit
186
1119
 
187
1120
  * \#1659 Clear delayed atomic sets when resetting the same embedded relation.
188
1121
 
189
- * \#1656/#1657 Don't hit database for uniqueness validation if BOTH scope
1122
+ * \#1656/\#1657 Don't hit database for uniqueness validation if BOTH scope
190
1123
  and attribute hasn't changed. (priyaaank)
191
1124
 
192
- * \#1205/#1642 When limiting fields returned from the database via
1125
+ * \#1205/\#1642 When limiting fields returned from the database via
193
1126
  `Criteria#only` and `Criteria#without` and then subsequently saving
194
1127
  the document. Default values no longer override excluded fields.
195
1128
 
@@ -200,16 +1133,18 @@ For instructions on upgrading to newer versions, visit
200
1133
  * \#1647 DateTime serialization when already in UTC does not convert to
201
1134
  local time.
202
1135
 
1136
+ * \#1641/\#1639 Mongoid.observer.disable :all now behaves as AR does.
1137
+
203
1138
  * \#1640 Update consumers should be tied to the name of the collection
204
1139
  they persist to, not the name of the class.
205
1140
 
206
- * \#1636 Scopes no longer modify parent class scopes when subclassing.
1141
+ * \#1637/\#1636 Scopes no longer modify parent class scopes when subclassing.
207
1142
  (Hans Hasselberg)
208
1143
 
209
1144
  * \#1629 $all and $in criteria on embedded many relations now properly
210
1145
  handles regex searches and elements of varying length. (Douwe Maan)
211
1146
 
212
- * \#1623 Default scopes no longer break Mongoid::Versioning.
1147
+ * \#1623/\#1634 Default scopes no longer break Mongoid::Versioning.
213
1148
  (Hans Hasselberg)
214
1149
 
215
1150
  * \#1605 Fix regression of rescue responses, Rails 3.2
@@ -218,6 +1153,10 @@ For instructions on upgrading to newer versions, visit
218
1153
 
219
1154
  ### Resolved Issues
220
1155
 
1156
+ * \#1628 _type field can once again be included in serialization to json
1157
+ or xml as a global option with `include_type_for_serialization`.
1158
+ (Roman Shterenzon)
1159
+
221
1160
  * \#1627 Validating format now works properly with localized fields.
222
1161
  (Douwe Maan)
223
1162