mongoid_heroku_stable 4.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 (660) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3235 -0
  3. data/LICENSE +20 -0
  4. data/README.md +62 -0
  5. data/Rakefile +35 -0
  6. data/lib/config/locales/en.yml +452 -0
  7. data/lib/mongoid.rb +104 -0
  8. data/lib/mongoid/atomic.rb +384 -0
  9. data/lib/mongoid/atomic/modifiers.rb +317 -0
  10. data/lib/mongoid/atomic/paths.rb +3 -0
  11. data/lib/mongoid/atomic/paths/embedded.rb +28 -0
  12. data/lib/mongoid/atomic/paths/embedded/many.rb +44 -0
  13. data/lib/mongoid/atomic/paths/embedded/one.rb +43 -0
  14. data/lib/mongoid/atomic/paths/root.rb +39 -0
  15. data/lib/mongoid/attributes.rb +305 -0
  16. data/lib/mongoid/attributes/dynamic.rb +154 -0
  17. data/lib/mongoid/attributes/nested.rb +82 -0
  18. data/lib/mongoid/attributes/processing.rb +147 -0
  19. data/lib/mongoid/attributes/readonly.rb +56 -0
  20. data/lib/mongoid/changeable.rb +379 -0
  21. data/lib/mongoid/composable.rb +104 -0
  22. data/lib/mongoid/config.rb +263 -0
  23. data/lib/mongoid/config/environment.rb +44 -0
  24. data/lib/mongoid/config/options.rb +74 -0
  25. data/lib/mongoid/config/validators.rb +3 -0
  26. data/lib/mongoid/config/validators/option.rb +25 -0
  27. data/lib/mongoid/config/validators/session.rb +140 -0
  28. data/lib/mongoid/contextual.rb +54 -0
  29. data/lib/mongoid/contextual/aggregable/memory.rb +109 -0
  30. data/lib/mongoid/contextual/aggregable/mongo.rb +145 -0
  31. data/lib/mongoid/contextual/atomic.rb +180 -0
  32. data/lib/mongoid/contextual/command.rb +61 -0
  33. data/lib/mongoid/contextual/eager.rb +158 -0
  34. data/lib/mongoid/contextual/find_and_modify.rb +69 -0
  35. data/lib/mongoid/contextual/geo_near.rb +238 -0
  36. data/lib/mongoid/contextual/map_reduce.rb +324 -0
  37. data/lib/mongoid/contextual/memory.rb +440 -0
  38. data/lib/mongoid/contextual/mongo.rb +676 -0
  39. data/lib/mongoid/contextual/queryable.rb +25 -0
  40. data/lib/mongoid/contextual/text_search.rb +180 -0
  41. data/lib/mongoid/copyable.rb +67 -0
  42. data/lib/mongoid/criteria.rb +562 -0
  43. data/lib/mongoid/criteria/findable.rb +179 -0
  44. data/lib/mongoid/criteria/inspectable.rb +25 -0
  45. data/lib/mongoid/criteria/marshalable.rb +50 -0
  46. data/lib/mongoid/criteria/modifiable.rb +189 -0
  47. data/lib/mongoid/criteria/scopable.rb +158 -0
  48. data/lib/mongoid/document.rb +361 -0
  49. data/lib/mongoid/equality.rb +66 -0
  50. data/lib/mongoid/errors.rb +41 -0
  51. data/lib/mongoid/errors/ambiguous_relationship.rb +51 -0
  52. data/lib/mongoid/errors/callback.rb +25 -0
  53. data/lib/mongoid/errors/delete_restriction.rb +29 -0
  54. data/lib/mongoid/errors/document_not_found.rb +111 -0
  55. data/lib/mongoid/errors/eager_load.rb +22 -0
  56. data/lib/mongoid/errors/invalid_collection.rb +18 -0
  57. data/lib/mongoid/errors/invalid_config_option.rb +27 -0
  58. data/lib/mongoid/errors/invalid_field.rb +64 -0
  59. data/lib/mongoid/errors/invalid_field_option.rb +35 -0
  60. data/lib/mongoid/errors/invalid_find.rb +19 -0
  61. data/lib/mongoid/errors/invalid_includes.rb +32 -0
  62. data/lib/mongoid/errors/invalid_index.rb +28 -0
  63. data/lib/mongoid/errors/invalid_options.rb +28 -0
  64. data/lib/mongoid/errors/invalid_path.rb +21 -0
  65. data/lib/mongoid/errors/invalid_scope.rb +24 -0
  66. data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +38 -0
  67. data/lib/mongoid/errors/invalid_storage_options.rb +27 -0
  68. data/lib/mongoid/errors/invalid_time.rb +22 -0
  69. data/lib/mongoid/errors/invalid_value.rb +16 -0
  70. data/lib/mongoid/errors/inverse_not_found.rb +29 -0
  71. data/lib/mongoid/errors/mixed_relations.rb +32 -0
  72. data/lib/mongoid/errors/mixed_session_configuration.rb +28 -0
  73. data/lib/mongoid/errors/mongoid_error.rb +92 -0
  74. data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +28 -0
  75. data/lib/mongoid/errors/no_default_session.rb +23 -0
  76. data/lib/mongoid/errors/no_environment.rb +19 -0
  77. data/lib/mongoid/errors/no_map_reduce_output.rb +24 -0
  78. data/lib/mongoid/errors/no_metadata.rb +21 -0
  79. data/lib/mongoid/errors/no_parent.rb +24 -0
  80. data/lib/mongoid/errors/no_session_config.rb +22 -0
  81. data/lib/mongoid/errors/no_session_database.rb +27 -0
  82. data/lib/mongoid/errors/no_session_hosts.rb +27 -0
  83. data/lib/mongoid/errors/no_sessions_config.rb +20 -0
  84. data/lib/mongoid/errors/readonly_attribute.rb +25 -0
  85. data/lib/mongoid/errors/scope_overwrite.rb +21 -0
  86. data/lib/mongoid/errors/too_many_nested_attribute_records.rb +20 -0
  87. data/lib/mongoid/errors/unknown_attribute.rb +25 -0
  88. data/lib/mongoid/errors/unsaved_document.rb +19 -0
  89. data/lib/mongoid/errors/unsupported_javascript.rb +27 -0
  90. data/lib/mongoid/errors/validations.rb +29 -0
  91. data/lib/mongoid/evolvable.rb +19 -0
  92. data/lib/mongoid/extensions.rb +35 -0
  93. data/lib/mongoid/extensions/array.rb +180 -0
  94. data/lib/mongoid/extensions/big_decimal.rb +69 -0
  95. data/lib/mongoid/extensions/boolean.rb +21 -0
  96. data/lib/mongoid/extensions/date.rb +77 -0
  97. data/lib/mongoid/extensions/date_time.rb +73 -0
  98. data/lib/mongoid/extensions/false_class.rb +38 -0
  99. data/lib/mongoid/extensions/float.rb +56 -0
  100. data/lib/mongoid/extensions/hash.rb +209 -0
  101. data/lib/mongoid/extensions/integer.rb +67 -0
  102. data/lib/mongoid/extensions/module.rb +28 -0
  103. data/lib/mongoid/extensions/nil_class.rb +33 -0
  104. data/lib/mongoid/extensions/object.rb +274 -0
  105. data/lib/mongoid/extensions/object_id.rb +54 -0
  106. data/lib/mongoid/extensions/range.rb +85 -0
  107. data/lib/mongoid/extensions/regexp.rb +27 -0
  108. data/lib/mongoid/extensions/set.rb +55 -0
  109. data/lib/mongoid/extensions/string.rb +199 -0
  110. data/lib/mongoid/extensions/symbol.rb +54 -0
  111. data/lib/mongoid/extensions/time.rb +88 -0
  112. data/lib/mongoid/extensions/time_with_zone.rb +56 -0
  113. data/lib/mongoid/extensions/true_class.rb +38 -0
  114. data/lib/mongoid/factory.rb +46 -0
  115. data/lib/mongoid/fields.rb +542 -0
  116. data/lib/mongoid/fields/foreign_key.rb +174 -0
  117. data/lib/mongoid/fields/localized.rb +73 -0
  118. data/lib/mongoid/fields/standard.rb +273 -0
  119. data/lib/mongoid/fields/validators.rb +2 -0
  120. data/lib/mongoid/fields/validators/macro.rb +92 -0
  121. data/lib/mongoid/findable.rb +133 -0
  122. data/lib/mongoid/identity_map.rb +163 -0
  123. data/lib/mongoid/indexable.rb +147 -0
  124. data/lib/mongoid/indexable/specification.rb +115 -0
  125. data/lib/mongoid/indexable/validators/options.rb +103 -0
  126. data/lib/mongoid/inspectable.rb +59 -0
  127. data/lib/mongoid/interceptable.rb +265 -0
  128. data/lib/mongoid/loggable.rb +69 -0
  129. data/lib/mongoid/matchable.rb +152 -0
  130. data/lib/mongoid/matchable/all.rb +27 -0
  131. data/lib/mongoid/matchable/and.rb +30 -0
  132. data/lib/mongoid/matchable/default.rb +72 -0
  133. data/lib/mongoid/matchable/exists.rb +23 -0
  134. data/lib/mongoid/matchable/gt.rb +21 -0
  135. data/lib/mongoid/matchable/gte.rb +21 -0
  136. data/lib/mongoid/matchable/in.rb +24 -0
  137. data/lib/mongoid/matchable/lt.rb +21 -0
  138. data/lib/mongoid/matchable/lte.rb +21 -0
  139. data/lib/mongoid/matchable/ne.rb +21 -0
  140. data/lib/mongoid/matchable/nin.rb +21 -0
  141. data/lib/mongoid/matchable/or.rb +33 -0
  142. data/lib/mongoid/matchable/size.rb +21 -0
  143. data/lib/mongoid/persistable.rb +207 -0
  144. data/lib/mongoid/persistable/creatable.rb +189 -0
  145. data/lib/mongoid/persistable/deletable.rb +149 -0
  146. data/lib/mongoid/persistable/destroyable.rb +55 -0
  147. data/lib/mongoid/persistable/incrementable.rb +36 -0
  148. data/lib/mongoid/persistable/logical.rb +38 -0
  149. data/lib/mongoid/persistable/poppable.rb +39 -0
  150. data/lib/mongoid/persistable/pullable.rb +55 -0
  151. data/lib/mongoid/persistable/pushable.rb +62 -0
  152. data/lib/mongoid/persistable/renamable.rb +35 -0
  153. data/lib/mongoid/persistable/savable.rb +52 -0
  154. data/lib/mongoid/persistable/settable.rb +33 -0
  155. data/lib/mongoid/persistable/unsettable.rb +36 -0
  156. data/lib/mongoid/persistable/updatable.rb +151 -0
  157. data/lib/mongoid/persistable/upsertable.rb +55 -0
  158. data/lib/mongoid/positional.rb +71 -0
  159. data/lib/mongoid/railtie.rb +156 -0
  160. data/lib/mongoid/railties/database.rake +97 -0
  161. data/lib/mongoid/railties/document.rb +12 -0
  162. data/lib/mongoid/relations.rb +162 -0
  163. data/lib/mongoid/relations/accessors.rb +299 -0
  164. data/lib/mongoid/relations/auto_save.rb +106 -0
  165. data/lib/mongoid/relations/binding.rb +218 -0
  166. data/lib/mongoid/relations/bindings.rb +9 -0
  167. data/lib/mongoid/relations/bindings/embedded/in.rb +63 -0
  168. data/lib/mongoid/relations/bindings/embedded/many.rb +50 -0
  169. data/lib/mongoid/relations/bindings/embedded/one.rb +55 -0
  170. data/lib/mongoid/relations/bindings/referenced/in.rb +65 -0
  171. data/lib/mongoid/relations/bindings/referenced/many.rb +42 -0
  172. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +67 -0
  173. data/lib/mongoid/relations/bindings/referenced/one.rb +44 -0
  174. data/lib/mongoid/relations/builder.rb +57 -0
  175. data/lib/mongoid/relations/builders.rb +104 -0
  176. data/lib/mongoid/relations/builders/embedded/in.rb +29 -0
  177. data/lib/mongoid/relations/builders/embedded/many.rb +36 -0
  178. data/lib/mongoid/relations/builders/embedded/one.rb +30 -0
  179. data/lib/mongoid/relations/builders/nested_attributes/many.rb +174 -0
  180. data/lib/mongoid/relations/builders/nested_attributes/one.rb +126 -0
  181. data/lib/mongoid/relations/builders/referenced/in.rb +26 -0
  182. data/lib/mongoid/relations/builders/referenced/many.rb +27 -0
  183. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +40 -0
  184. data/lib/mongoid/relations/builders/referenced/one.rb +26 -0
  185. data/lib/mongoid/relations/cascading.rb +56 -0
  186. data/lib/mongoid/relations/cascading/delete.rb +44 -0
  187. data/lib/mongoid/relations/cascading/destroy.rb +43 -0
  188. data/lib/mongoid/relations/cascading/nullify.rb +35 -0
  189. data/lib/mongoid/relations/cascading/restrict.rb +39 -0
  190. data/lib/mongoid/relations/constraint.rb +49 -0
  191. data/lib/mongoid/relations/conversions.rb +34 -0
  192. data/lib/mongoid/relations/counter_cache.rb +105 -0
  193. data/lib/mongoid/relations/cyclic.rb +107 -0
  194. data/lib/mongoid/relations/embedded/batchable.rb +355 -0
  195. data/lib/mongoid/relations/embedded/in.rb +231 -0
  196. data/lib/mongoid/relations/embedded/many.rb +639 -0
  197. data/lib/mongoid/relations/embedded/one.rb +223 -0
  198. data/lib/mongoid/relations/macros.rb +356 -0
  199. data/lib/mongoid/relations/many.rb +208 -0
  200. data/lib/mongoid/relations/marshalable.rb +32 -0
  201. data/lib/mongoid/relations/metadata.rb +1172 -0
  202. data/lib/mongoid/relations/nested_builder.rb +74 -0
  203. data/lib/mongoid/relations/one.rb +60 -0
  204. data/lib/mongoid/relations/options.rb +48 -0
  205. data/lib/mongoid/relations/polymorphic.rb +39 -0
  206. data/lib/mongoid/relations/proxy.rb +270 -0
  207. data/lib/mongoid/relations/referenced/in.rb +297 -0
  208. data/lib/mongoid/relations/referenced/many.rb +787 -0
  209. data/lib/mongoid/relations/referenced/many_to_many.rb +486 -0
  210. data/lib/mongoid/relations/referenced/one.rb +290 -0
  211. data/lib/mongoid/relations/reflections.rb +62 -0
  212. data/lib/mongoid/relations/synchronization.rb +169 -0
  213. data/lib/mongoid/relations/targets.rb +2 -0
  214. data/lib/mongoid/relations/targets/enumerable.rb +473 -0
  215. data/lib/mongoid/relations/touchable.rb +94 -0
  216. data/lib/mongoid/reloadable.rb +95 -0
  217. data/lib/mongoid/scopable.rb +379 -0
  218. data/lib/mongoid/selectable.rb +59 -0
  219. data/lib/mongoid/serializable.rb +170 -0
  220. data/lib/mongoid/sessions.rb +330 -0
  221. data/lib/mongoid/sessions/factory.rb +129 -0
  222. data/lib/mongoid/sessions/mongo_uri.rb +93 -0
  223. data/lib/mongoid/sessions/options.rb +141 -0
  224. data/lib/mongoid/sessions/validators.rb +2 -0
  225. data/lib/mongoid/sessions/validators/storage.rb +49 -0
  226. data/lib/mongoid/shardable.rb +65 -0
  227. data/lib/mongoid/state.rb +97 -0
  228. data/lib/mongoid/threaded.rb +383 -0
  229. data/lib/mongoid/threaded/lifecycle.rb +164 -0
  230. data/lib/mongoid/timestamps.rb +15 -0
  231. data/lib/mongoid/timestamps/created.rb +30 -0
  232. data/lib/mongoid/timestamps/created/short.rb +19 -0
  233. data/lib/mongoid/timestamps/short.rb +10 -0
  234. data/lib/mongoid/timestamps/updated.rb +39 -0
  235. data/lib/mongoid/timestamps/updated/short.rb +19 -0
  236. data/lib/mongoid/traversable.rb +192 -0
  237. data/lib/mongoid/unit_of_work.rb +61 -0
  238. data/lib/mongoid/validatable.rb +180 -0
  239. data/lib/mongoid/validatable/associated.rb +48 -0
  240. data/lib/mongoid/validatable/format.rb +20 -0
  241. data/lib/mongoid/validatable/length.rb +20 -0
  242. data/lib/mongoid/validatable/localizable.rb +30 -0
  243. data/lib/mongoid/validatable/macros.rb +94 -0
  244. data/lib/mongoid/validatable/presence.rb +86 -0
  245. data/lib/mongoid/validatable/queryable.rb +30 -0
  246. data/lib/mongoid/validatable/uniqueness.rb +330 -0
  247. data/lib/mongoid/version.rb +4 -0
  248. data/lib/rack/mongoid.rb +2 -0
  249. data/lib/rack/mongoid/middleware/identity_map.rb +39 -0
  250. data/lib/rails/generators/mongoid/config/config_generator.rb +25 -0
  251. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +76 -0
  252. data/lib/rails/generators/mongoid/model/model_generator.rb +25 -0
  253. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +19 -0
  254. data/lib/rails/generators/mongoid/observer/observer_generator.rb +17 -0
  255. data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +4 -0
  256. data/lib/rails/generators/mongoid_generator.rb +65 -0
  257. data/lib/rails/mongoid.rb +180 -0
  258. data/lib/support/ruby_version.rb +26 -0
  259. data/spec/app/models/account.rb +28 -0
  260. data/spec/app/models/acolyte.rb +17 -0
  261. data/spec/app/models/actor.rb +18 -0
  262. data/spec/app/models/actress.rb +2 -0
  263. data/spec/app/models/address.rb +77 -0
  264. data/spec/app/models/address_component.rb +5 -0
  265. data/spec/app/models/address_number.rb +6 -0
  266. data/spec/app/models/agency.rb +5 -0
  267. data/spec/app/models/agent.rb +12 -0
  268. data/spec/app/models/album.rb +14 -0
  269. data/spec/app/models/alert.rb +5 -0
  270. data/spec/app/models/animal.rb +25 -0
  271. data/spec/app/models/answer.rb +4 -0
  272. data/spec/app/models/appointment.rb +7 -0
  273. data/spec/app/models/article.rb +10 -0
  274. data/spec/app/models/artist.rb +66 -0
  275. data/spec/app/models/artwork.rb +4 -0
  276. data/spec/app/models/audio.rb +5 -0
  277. data/spec/app/models/augmentation.rb +11 -0
  278. data/spec/app/models/author.rb +4 -0
  279. data/spec/app/models/band.rb +26 -0
  280. data/spec/app/models/bar.rb +10 -0
  281. data/spec/app/models/basic.rb +6 -0
  282. data/spec/app/models/bed.rb +1 -0
  283. data/spec/app/models/big_palette.rb +2 -0
  284. data/spec/app/models/birthday.rb +13 -0
  285. data/spec/app/models/book.rb +13 -0
  286. data/spec/app/models/breed.rb +4 -0
  287. data/spec/app/models/browser.rb +6 -0
  288. data/spec/app/models/building.rb +5 -0
  289. data/spec/app/models/building_address.rb +5 -0
  290. data/spec/app/models/bus.rb +7 -0
  291. data/spec/app/models/business.rb +5 -0
  292. data/spec/app/models/callback_recorder.rb +25 -0
  293. data/spec/app/models/callback_test.rb +9 -0
  294. data/spec/app/models/canvas.rb +25 -0
  295. data/spec/app/models/car.rb +1 -0
  296. data/spec/app/models/cat.rb +8 -0
  297. data/spec/app/models/category.rb +8 -0
  298. data/spec/app/models/child.rb +4 -0
  299. data/spec/app/models/child_doc.rb +22 -0
  300. data/spec/app/models/church.rb +4 -0
  301. data/spec/app/models/circle.rb +3 -0
  302. data/spec/app/models/circuit.rb +4 -0
  303. data/spec/app/models/circus.rb +7 -0
  304. data/spec/app/models/code.rb +5 -0
  305. data/spec/app/models/comment.rb +16 -0
  306. data/spec/app/models/contractor.rb +5 -0
  307. data/spec/app/models/cookie.rb +6 -0
  308. data/spec/app/models/country_code.rb +8 -0
  309. data/spec/app/models/definition.rb +7 -0
  310. data/spec/app/models/description.rb +11 -0
  311. data/spec/app/models/dictionary.rb +10 -0
  312. data/spec/app/models/division.rb +10 -0
  313. data/spec/app/models/doctor.rb +12 -0
  314. data/spec/app/models/dog.rb +7 -0
  315. data/spec/app/models/dokument.rb +5 -0
  316. data/spec/app/models/dragon.rb +4 -0
  317. data/spec/app/models/driver.rb +7 -0
  318. data/spec/app/models/drug.rb +6 -0
  319. data/spec/app/models/dungeon.rb +4 -0
  320. data/spec/app/models/email.rb +6 -0
  321. data/spec/app/models/employer.rb +5 -0
  322. data/spec/app/models/entry.rb +6 -0
  323. data/spec/app/models/eraser.rb +1 -0
  324. data/spec/app/models/event.rb +22 -0
  325. data/spec/app/models/exhibition.rb +4 -0
  326. data/spec/app/models/exhibitor.rb +5 -0
  327. data/spec/app/models/eye.rb +9 -0
  328. data/spec/app/models/eye_bowl.rb +9 -0
  329. data/spec/app/models/face.rb +8 -0
  330. data/spec/app/models/favorite.rb +6 -0
  331. data/spec/app/models/filesystem.rb +5 -0
  332. data/spec/app/models/fire_hydrant.rb +6 -0
  333. data/spec/app/models/firefox.rb +4 -0
  334. data/spec/app/models/fish.rb +7 -0
  335. data/spec/app/models/folder.rb +7 -0
  336. data/spec/app/models/folder_item.rb +9 -0
  337. data/spec/app/models/fruits.rb +34 -0
  338. data/spec/app/models/game.rb +19 -0
  339. data/spec/app/models/ghost.rb +7 -0
  340. data/spec/app/models/home.rb +4 -0
  341. data/spec/app/models/house.rb +6 -0
  342. data/spec/app/models/html_writer.rb +3 -0
  343. data/spec/app/models/image.rb +22 -0
  344. data/spec/app/models/implant.rb +16 -0
  345. data/spec/app/models/item.rb +8 -0
  346. data/spec/app/models/jar.rb +7 -0
  347. data/spec/app/models/label.rb +40 -0
  348. data/spec/app/models/language.rb +5 -0
  349. data/spec/app/models/lat_lng.rb +15 -0
  350. data/spec/app/models/league.rb +11 -0
  351. data/spec/app/models/learner.rb +2 -0
  352. data/spec/app/models/line_item.rb +6 -0
  353. data/spec/app/models/location.rb +8 -0
  354. data/spec/app/models/login.rb +8 -0
  355. data/spec/app/models/manufacturer.rb +7 -0
  356. data/spec/app/models/meat.rb +4 -0
  357. data/spec/app/models/membership.rb +4 -0
  358. data/spec/app/models/mixed_drink.rb +4 -0
  359. data/spec/app/models/movie.rb +13 -0
  360. data/spec/app/models/my_hash.rb +2 -0
  361. data/spec/app/models/name.rb +23 -0
  362. data/spec/app/models/node.rb +5 -0
  363. data/spec/app/models/note.rb +12 -0
  364. data/spec/app/models/ordered_post.rb +6 -0
  365. data/spec/app/models/ordered_preference.rb +6 -0
  366. data/spec/app/models/oscar.rb +15 -0
  367. data/spec/app/models/override.rb +16 -0
  368. data/spec/app/models/ownable.rb +6 -0
  369. data/spec/app/models/owner.rb +6 -0
  370. data/spec/app/models/pack.rb +3 -0
  371. data/spec/app/models/page.rb +5 -0
  372. data/spec/app/models/page_question.rb +4 -0
  373. data/spec/app/models/palette.rb +7 -0
  374. data/spec/app/models/parent.rb +5 -0
  375. data/spec/app/models/parent_doc.rb +6 -0
  376. data/spec/app/models/passport.rb +5 -0
  377. data/spec/app/models/patient.rb +9 -0
  378. data/spec/app/models/pdf_writer.rb +3 -0
  379. data/spec/app/models/pencil.rb +1 -0
  380. data/spec/app/models/person.rb +206 -0
  381. data/spec/app/models/pet.rb +23 -0
  382. data/spec/app/models/pet_owner.rb +6 -0
  383. data/spec/app/models/phone.rb +11 -0
  384. data/spec/app/models/pizza.rb +7 -0
  385. data/spec/app/models/player.rb +35 -0
  386. data/spec/app/models/post.rb +44 -0
  387. data/spec/app/models/powerup.rb +11 -0
  388. data/spec/app/models/preference.rb +9 -0
  389. data/spec/app/models/princess.rb +8 -0
  390. data/spec/app/models/product.rb +15 -0
  391. data/spec/app/models/profile.rb +5 -0
  392. data/spec/app/models/pronunciation.rb +5 -0
  393. data/spec/app/models/purchase.rb +4 -0
  394. data/spec/app/models/question.rb +8 -0
  395. data/spec/app/models/quiz.rb +7 -0
  396. data/spec/app/models/rating.rb +8 -0
  397. data/spec/app/models/record.rb +46 -0
  398. data/spec/app/models/registry.rb +4 -0
  399. data/spec/app/models/role.rb +7 -0
  400. data/spec/app/models/root_category.rb +4 -0
  401. data/spec/app/models/sandwich.rb +4 -0
  402. data/spec/app/models/scheduler.rb +7 -0
  403. data/spec/app/models/seo.rb +7 -0
  404. data/spec/app/models/series.rb +4 -0
  405. data/spec/app/models/server.rb +13 -0
  406. data/spec/app/models/service.rb +22 -0
  407. data/spec/app/models/shape.rb +12 -0
  408. data/spec/app/models/shelf.rb +5 -0
  409. data/spec/app/models/shipping_container.rb +5 -0
  410. data/spec/app/models/shipping_pack.rb +3 -0
  411. data/spec/app/models/shop.rb +6 -0
  412. data/spec/app/models/short_agent.rb +4 -0
  413. data/spec/app/models/short_quiz.rb +5 -0
  414. data/spec/app/models/slave.rb +6 -0
  415. data/spec/app/models/song.rb +8 -0
  416. data/spec/app/models/sound.rb +5 -0
  417. data/spec/app/models/square.rb +4 -0
  418. data/spec/app/models/strategy.rb +3 -0
  419. data/spec/app/models/sub_item.rb +3 -0
  420. data/spec/app/models/subscription.rb +4 -0
  421. data/spec/app/models/survey.rb +5 -0
  422. data/spec/app/models/symptom.rb +6 -0
  423. data/spec/app/models/tag.rb +8 -0
  424. data/spec/app/models/target.rb +5 -0
  425. data/spec/app/models/template.rb +5 -0
  426. data/spec/app/models/thing.rb +9 -0
  427. data/spec/app/models/title.rb +3 -0
  428. data/spec/app/models/tool.rb +8 -0
  429. data/spec/app/models/topping.rb +5 -0
  430. data/spec/app/models/track.rb +38 -0
  431. data/spec/app/models/translation.rb +5 -0
  432. data/spec/app/models/tree.rb +9 -0
  433. data/spec/app/models/truck.rb +3 -0
  434. data/spec/app/models/user.rb +21 -0
  435. data/spec/app/models/user_account.rb +10 -0
  436. data/spec/app/models/validation_callback.rb +10 -0
  437. data/spec/app/models/vehicle.rb +11 -0
  438. data/spec/app/models/version.rb +5 -0
  439. data/spec/app/models/vet_visit.rb +5 -0
  440. data/spec/app/models/video.rb +13 -0
  441. data/spec/app/models/weapon.rb +11 -0
  442. data/spec/app/models/wiki_page.rb +14 -0
  443. data/spec/app/models/word.rb +15 -0
  444. data/spec/app/models/word_origin.rb +11 -0
  445. data/spec/app/models/writer.rb +11 -0
  446. data/spec/config/mongoid.yml +38 -0
  447. data/spec/mongoid/atomic/modifiers_spec.rb +456 -0
  448. data/spec/mongoid/atomic/paths/embedded/many_spec.rb +118 -0
  449. data/spec/mongoid/atomic/paths/embedded/one_spec.rb +110 -0
  450. data/spec/mongoid/atomic/paths/root_spec.rb +48 -0
  451. data/spec/mongoid/atomic/paths_spec.rb +270 -0
  452. data/spec/mongoid/atomic_spec.rb +365 -0
  453. data/spec/mongoid/attributes/nested_spec.rb +4832 -0
  454. data/spec/mongoid/attributes/readonly_spec.rb +169 -0
  455. data/spec/mongoid/attributes_spec.rb +1467 -0
  456. data/spec/mongoid/changeable_spec.rb +1507 -0
  457. data/spec/mongoid/composable_spec.rb +24 -0
  458. data/spec/mongoid/config/environment_spec.rb +83 -0
  459. data/spec/mongoid/config/options_spec.rb +56 -0
  460. data/spec/mongoid/config_spec.rb +318 -0
  461. data/spec/mongoid/contextual/aggregable/memory_spec.rb +293 -0
  462. data/spec/mongoid/contextual/aggregable/mongo_spec.rb +495 -0
  463. data/spec/mongoid/contextual/atomic_spec.rb +529 -0
  464. data/spec/mongoid/contextual/find_and_modify_spec.rb +220 -0
  465. data/spec/mongoid/contextual/geo_near_spec.rb +405 -0
  466. data/spec/mongoid/contextual/map_reduce_spec.rb +464 -0
  467. data/spec/mongoid/contextual/memory_spec.rb +1236 -0
  468. data/spec/mongoid/contextual/mongo_spec.rb +1843 -0
  469. data/spec/mongoid/contextual/text_search_spec.rb +207 -0
  470. data/spec/mongoid/copyable_spec.rb +393 -0
  471. data/spec/mongoid/criteria/findable_spec.rb +1222 -0
  472. data/spec/mongoid/criteria/inspectable_spec.rb +27 -0
  473. data/spec/mongoid/criteria/marshalable_spec.rb +28 -0
  474. data/spec/mongoid/criteria/modifiable_spec.rb +1063 -0
  475. data/spec/mongoid/criteria/scopable_spec.rb +391 -0
  476. data/spec/mongoid/criteria_spec.rb +3821 -0
  477. data/spec/mongoid/document_spec.rb +1205 -0
  478. data/spec/mongoid/equality_spec.rb +241 -0
  479. data/spec/mongoid/errors/ambiguous_relationship_spec.rb +29 -0
  480. data/spec/mongoid/errors/callback_spec.rb +29 -0
  481. data/spec/mongoid/errors/delete_restriction_spec.rb +29 -0
  482. data/spec/mongoid/errors/document_not_found_spec.rb +104 -0
  483. data/spec/mongoid/errors/eager_load_spec.rb +29 -0
  484. data/spec/mongoid/errors/invalid_collection_spec.rb +36 -0
  485. data/spec/mongoid/errors/invalid_config_option_spec.rb +29 -0
  486. data/spec/mongoid/errors/invalid_field_option_spec.rb +29 -0
  487. data/spec/mongoid/errors/invalid_field_spec.rb +37 -0
  488. data/spec/mongoid/errors/invalid_find_spec.rb +29 -0
  489. data/spec/mongoid/errors/invalid_includes_spec.rb +40 -0
  490. data/spec/mongoid/errors/invalid_index_spec.rb +29 -0
  491. data/spec/mongoid/errors/invalid_options_spec.rb +29 -0
  492. data/spec/mongoid/errors/invalid_path_spec.rb +23 -0
  493. data/spec/mongoid/errors/invalid_scope_spec.rb +29 -0
  494. data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +17 -0
  495. data/spec/mongoid/errors/invalid_storage_options_spec.rb +29 -0
  496. data/spec/mongoid/errors/invalid_time_spec.rb +29 -0
  497. data/spec/mongoid/errors/inverse_not_found_spec.rb +29 -0
  498. data/spec/mongoid/errors/mixed_relations_spec.rb +29 -0
  499. data/spec/mongoid/errors/mixed_session_configuration_spec.rb +29 -0
  500. data/spec/mongoid/errors/mongoid_error_spec.rb +48 -0
  501. data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +29 -0
  502. data/spec/mongoid/errors/no_environment_spec.rb +29 -0
  503. data/spec/mongoid/errors/no_map_reduce_output_spec.rb +29 -0
  504. data/spec/mongoid/errors/no_metadata_spec.rb +23 -0
  505. data/spec/mongoid/errors/no_parent_spec.rb +29 -0
  506. data/spec/mongoid/errors/no_session_config_spec.rb +29 -0
  507. data/spec/mongoid/errors/no_session_database_spec.rb +29 -0
  508. data/spec/mongoid/errors/no_session_hosts_spec.rb +29 -0
  509. data/spec/mongoid/errors/no_sessions_config_spec.rb +29 -0
  510. data/spec/mongoid/errors/readonly_attribute_spec.rb +29 -0
  511. data/spec/mongoid/errors/scope_overwrite_spec.rb +29 -0
  512. data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +29 -0
  513. data/spec/mongoid/errors/unknown_attribute_spec.rb +29 -0
  514. data/spec/mongoid/errors/unsaved_document_spec.rb +37 -0
  515. data/spec/mongoid/errors/unsupported_javascript_spec.rb +29 -0
  516. data/spec/mongoid/errors/validations_spec.rb +45 -0
  517. data/spec/mongoid/extensions/array_spec.rb +638 -0
  518. data/spec/mongoid/extensions/big_decimal_spec.rb +104 -0
  519. data/spec/mongoid/extensions/binary_spec.rb +60 -0
  520. data/spec/mongoid/extensions/boolean_spec.rb +135 -0
  521. data/spec/mongoid/extensions/date_spec.rb +235 -0
  522. data/spec/mongoid/extensions/date_time_spec.rb +155 -0
  523. data/spec/mongoid/extensions/false_class_spec.rb +42 -0
  524. data/spec/mongoid/extensions/float_spec.rb +133 -0
  525. data/spec/mongoid/extensions/hash_spec.rb +333 -0
  526. data/spec/mongoid/extensions/integer_spec.rb +136 -0
  527. data/spec/mongoid/extensions/module_spec.rb +42 -0
  528. data/spec/mongoid/extensions/nil_class_spec.rb +11 -0
  529. data/spec/mongoid/extensions/object_id_spec.rb +946 -0
  530. data/spec/mongoid/extensions/object_spec.rb +292 -0
  531. data/spec/mongoid/extensions/range_spec.rb +154 -0
  532. data/spec/mongoid/extensions/regexp_spec.rb +47 -0
  533. data/spec/mongoid/extensions/set_spec.rb +33 -0
  534. data/spec/mongoid/extensions/string_spec.rb +357 -0
  535. data/spec/mongoid/extensions/symbol_spec.rb +76 -0
  536. data/spec/mongoid/extensions/time_spec.rb +467 -0
  537. data/spec/mongoid/extensions/time_with_zone_spec.rb +405 -0
  538. data/spec/mongoid/extensions/true_class_spec.rb +42 -0
  539. data/spec/mongoid/extensions_spec.rb +15 -0
  540. data/spec/mongoid/factory_spec.rb +185 -0
  541. data/spec/mongoid/fields/foreign_key_spec.rb +694 -0
  542. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +184 -0
  543. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +201 -0
  544. data/spec/mongoid/fields/localized_spec.rb +386 -0
  545. data/spec/mongoid/fields/standard_spec.rb +166 -0
  546. data/spec/mongoid/fields_spec.rb +1229 -0
  547. data/spec/mongoid/findable_spec.rb +342 -0
  548. data/spec/mongoid/identity_map_spec.rb +564 -0
  549. data/spec/mongoid/indexable/specification_spec.rb +87 -0
  550. data/spec/mongoid/indexable_spec.rb +504 -0
  551. data/spec/mongoid/inspectable_spec.rb +49 -0
  552. data/spec/mongoid/interceptable_spec.rb +1564 -0
  553. data/spec/mongoid/loggable_spec.rb +21 -0
  554. data/spec/mongoid/matchable/all_spec.rb +31 -0
  555. data/spec/mongoid/matchable/and_spec.rb +162 -0
  556. data/spec/mongoid/matchable/default_spec.rb +130 -0
  557. data/spec/mongoid/matchable/exists_spec.rb +57 -0
  558. data/spec/mongoid/matchable/gt_spec.rb +75 -0
  559. data/spec/mongoid/matchable/gte_spec.rb +74 -0
  560. data/spec/mongoid/matchable/in_spec.rb +25 -0
  561. data/spec/mongoid/matchable/lt_spec.rb +74 -0
  562. data/spec/mongoid/matchable/lte_spec.rb +74 -0
  563. data/spec/mongoid/matchable/ne_spec.rb +25 -0
  564. data/spec/mongoid/matchable/nin_spec.rb +25 -0
  565. data/spec/mongoid/matchable/or_spec.rb +106 -0
  566. data/spec/mongoid/matchable/size_spec.rb +25 -0
  567. data/spec/mongoid/matchable_spec.rb +532 -0
  568. data/spec/mongoid/persistable/creatable_spec.rb +512 -0
  569. data/spec/mongoid/persistable/deletable_spec.rb +205 -0
  570. data/spec/mongoid/persistable/destroyable_spec.rb +148 -0
  571. data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
  572. data/spec/mongoid/persistable/logical_spec.rb +143 -0
  573. data/spec/mongoid/persistable/poppable_spec.rb +115 -0
  574. data/spec/mongoid/persistable/pullable_spec.rb +228 -0
  575. data/spec/mongoid/persistable/pushable_spec.rb +258 -0
  576. data/spec/mongoid/persistable/renamable_spec.rb +135 -0
  577. data/spec/mongoid/persistable/savable_spec.rb +432 -0
  578. data/spec/mongoid/persistable/settable_spec.rb +139 -0
  579. data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
  580. data/spec/mongoid/persistable/updatable_spec.rb +522 -0
  581. data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
  582. data/spec/mongoid/persistable_spec.rb +206 -0
  583. data/spec/mongoid/positional_spec.rb +227 -0
  584. data/spec/mongoid/railties/document_spec.rb +24 -0
  585. data/spec/mongoid/relations/accessors_spec.rb +736 -0
  586. data/spec/mongoid/relations/auto_save_spec.rb +261 -0
  587. data/spec/mongoid/relations/bindings/embedded/in_spec.rb +171 -0
  588. data/spec/mongoid/relations/bindings/embedded/many_spec.rb +54 -0
  589. data/spec/mongoid/relations/bindings/embedded/one_spec.rb +77 -0
  590. data/spec/mongoid/relations/bindings/referenced/in_spec.rb +241 -0
  591. data/spec/mongoid/relations/bindings/referenced/many_spec.rb +153 -0
  592. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +178 -0
  593. data/spec/mongoid/relations/bindings/referenced/one_spec.rb +131 -0
  594. data/spec/mongoid/relations/builders/embedded/in_spec.rb +34 -0
  595. data/spec/mongoid/relations/builders/embedded/many_spec.rb +132 -0
  596. data/spec/mongoid/relations/builders/embedded/one_spec.rb +99 -0
  597. data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +234 -0
  598. data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +250 -0
  599. data/spec/mongoid/relations/builders/referenced/in_spec.rb +241 -0
  600. data/spec/mongoid/relations/builders/referenced/many_spec.rb +137 -0
  601. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +178 -0
  602. data/spec/mongoid/relations/builders/referenced/one_spec.rb +124 -0
  603. data/spec/mongoid/relations/builders_spec.rb +226 -0
  604. data/spec/mongoid/relations/cascading/delete_spec.rb +101 -0
  605. data/spec/mongoid/relations/cascading/destroy_spec.rb +47 -0
  606. data/spec/mongoid/relations/cascading/nullify_spec.rb +32 -0
  607. data/spec/mongoid/relations/cascading/restrict_spec.rb +68 -0
  608. data/spec/mongoid/relations/cascading_spec.rb +355 -0
  609. data/spec/mongoid/relations/constraint_spec.rb +74 -0
  610. data/spec/mongoid/relations/conversions_spec.rb +126 -0
  611. data/spec/mongoid/relations/counter_cache_spec.rb +205 -0
  612. data/spec/mongoid/relations/cyclic_spec.rb +156 -0
  613. data/spec/mongoid/relations/embedded/dirty_spec.rb +65 -0
  614. data/spec/mongoid/relations/embedded/in_spec.rb +579 -0
  615. data/spec/mongoid/relations/embedded/many_spec.rb +3781 -0
  616. data/spec/mongoid/relations/embedded/one_spec.rb +1014 -0
  617. data/spec/mongoid/relations/macros_spec.rb +631 -0
  618. data/spec/mongoid/relations/metadata_spec.rb +1936 -0
  619. data/spec/mongoid/relations/options_spec.rb +35 -0
  620. data/spec/mongoid/relations/polymorphic_spec.rb +128 -0
  621. data/spec/mongoid/relations/proxy_spec.rb +48 -0
  622. data/spec/mongoid/relations/referenced/in_spec.rb +1435 -0
  623. data/spec/mongoid/relations/referenced/many_spec.rb +3546 -0
  624. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +3556 -0
  625. data/spec/mongoid/relations/referenced/one_spec.rb +1289 -0
  626. data/spec/mongoid/relations/reflections_spec.rb +101 -0
  627. data/spec/mongoid/relations/synchronization_spec.rb +449 -0
  628. data/spec/mongoid/relations/targets/enumerable_spec.rb +1710 -0
  629. data/spec/mongoid/relations/touchable_spec.rb +296 -0
  630. data/spec/mongoid/relations_spec.rb +188 -0
  631. data/spec/mongoid/reloadable_spec.rb +305 -0
  632. data/spec/mongoid/scopable_spec.rb +926 -0
  633. data/spec/mongoid/selectable_spec.rb +134 -0
  634. data/spec/mongoid/serializable_spec.rb +862 -0
  635. data/spec/mongoid/sessions/factory_spec.rb +312 -0
  636. data/spec/mongoid/sessions/mongo_uri_spec.rb +103 -0
  637. data/spec/mongoid/sessions/options_spec.rb +71 -0
  638. data/spec/mongoid/sessions_spec.rb +1078 -0
  639. data/spec/mongoid/shardable_spec.rb +61 -0
  640. data/spec/mongoid/state_spec.rb +102 -0
  641. data/spec/mongoid/threaded_spec.rb +258 -0
  642. data/spec/mongoid/timestamps/created/short_spec.rb +51 -0
  643. data/spec/mongoid/timestamps/created_spec.rb +44 -0
  644. data/spec/mongoid/timestamps/updated/short_spec.rb +90 -0
  645. data/spec/mongoid/timestamps/updated_spec.rb +86 -0
  646. data/spec/mongoid/timestamps_spec.rb +112 -0
  647. data/spec/mongoid/traversable_spec.rb +244 -0
  648. data/spec/mongoid/unit_of_work_spec.rb +196 -0
  649. data/spec/mongoid/validatable/associated_spec.rb +183 -0
  650. data/spec/mongoid/validatable/format_spec.rb +83 -0
  651. data/spec/mongoid/validatable/length_spec.rb +119 -0
  652. data/spec/mongoid/validatable/numericality_spec.rb +30 -0
  653. data/spec/mongoid/validatable/presence_spec.rb +511 -0
  654. data/spec/mongoid/validatable/uniqueness_spec.rb +2305 -0
  655. data/spec/mongoid/validatable_spec.rb +309 -0
  656. data/spec/mongoid_spec.rb +74 -0
  657. data/spec/rack/mongoid/middleware/identity_map_spec.rb +72 -0
  658. data/spec/rails/mongoid_spec.rb +462 -0
  659. data/spec/spec_helper.rb +103 -0
  660. metadata +1160 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93c8214c7154b80ee88be6112ae4cecc9d5cf1af
4
+ data.tar.gz: b44797988f27a8c1d3b00973bbe94a179a255b3d
5
+ SHA512:
6
+ metadata.gz: ae2e4da16d1512c2abd10c091a0d7bbda74716c7ae28e92d58721b2ed2c386a487a847abe3deee2daa5521b3abcffcea08302e02f4d14dc8b17f25fdacf279a6
7
+ data.tar.gz: 82e42e65a97ce3843781abbaddcefbf8f9c6a5c21d2961ee62e92cdff9cb7e69290f90f7e0945524e0ecb7be1a2469b22ad044a141290ffca7469e78f3408ebf
@@ -0,0 +1,3235 @@
1
+ # Overview
2
+
3
+ For instructions on upgrading to newer versions, visit
4
+ [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
+
6
+ ## 4.0.0
7
+
8
+ ### Major Changes (Backwards Incompatible)
9
+
10
+ * \#3230 Array and Hash fields now validate that the correct types are
11
+ getting set, instead of allowing any value. (Rodrigo Saito)
12
+
13
+ * \#3043/\#2949 Rework on the internals of persistence options. (Arthur Neves)
14
+
15
+ * Mongoid now requires Active Model 4 or higher.
16
+
17
+ * `Document#set` now accepts multiple attributes in the form of a hash,
18
+ instead of the previous `(field, value)` args. Field aliases and typecasting
19
+ are also now supported in this operation.
20
+
21
+ document.set(name: "Photek", likes: 10000)
22
+
23
+ * `Document#rename` now accepts multiple attributes in the form of a hash,
24
+ instead of the previous `(field, value)` args. Field aliases are supported.
25
+
26
+ document.rename(first_name: "fn", last_name: "ln")
27
+
28
+ * `Document#inc` now accepts multiple attributes in the form of a hash, instead
29
+ of previously only being able to increment one value at a time. Aliases and
30
+ serialization is supported.
31
+
32
+ document.inc(score: 10, place: -1, lives: -10)
33
+
34
+ * `Document#pop` now accepts multiple attributes in the form of a hash, instead
35
+ of previously only being able to pop one value at a time. Aliases and
36
+ serialization is supported.
37
+
38
+ document.pop(names: 1, aliases: -1)
39
+
40
+ * `Document#bit` now accepts multiple attributes in the form of a hash, instead
41
+ of previously only being able to apply one set of operations at a time.
42
+ Aliases and serialization are supported.
43
+
44
+ document.bit(age: { and: 13 }, score: { or: 13 })
45
+
46
+ * `Document#pull` now accepts multiple attributes in the form of a hash, instead
47
+ of previously only being able to pull one value at a time. Aliases and
48
+ serialization is supported.
49
+
50
+ document.pull(names: "James", aliases: "007")
51
+
52
+ * `Document#pull_all` now accepts multiple attributes in the form of a hash,
53
+ instead of previously only being able to pull one value at a time. Aliases and
54
+ serialization is supported.
55
+
56
+ document.pull_all(names: ["James", "Bond"], aliases: ["007"])
57
+
58
+ * `Document#push_all` has been removed since it was deprecated in MongoDB 2.4.
59
+ Use `Document.push` instead.
60
+
61
+ * `Document#push` now accepts multiple attributes in the form of a hash, and
62
+ can handle the pushing of single values or multiple values to the field via
63
+ $push with $each. Aliases and serialization is supported.
64
+
65
+ document.push(names: "James", aliases: [ "007", "Jim" ])
66
+
67
+ * `Document#add_to_set` now accepts multiple attributes in the form of a hash,
68
+ and now aliases and serialization are supported.
69
+
70
+ document.add_to_set(names: "James", aliases: "007")
71
+
72
+ * Criteria atomic operations API is now changed to match the changes in the
73
+ single document atomic API, for example:
74
+
75
+ Band.where(name: "Depeche Mode").inc(likes: 10, followers: 20)
76
+
77
+ * \#3138 `update_attributes` can now be accessed simply by calling `update`.
78
+
79
+ * \#3083 A new rake task: `rake mongoid:remove_undefined_indexes` has been added to
80
+ remove indexes from the database that are not explicitly defined in the models.
81
+ (Aidan Feldman)
82
+
83
+ * \#3029 The `relation_field` field that is added for a single use case with polymorphic
84
+ relations has been removed. So where the following would work before:
85
+
86
+ class Eye
87
+ include Mongoid::Document
88
+ belongs_to :eyeable, polymorphic: true
89
+ end
90
+
91
+ class Face
92
+ include Mongoid::Document
93
+ has_one :left_eye, class_name: "Eye", as: :eyeable
94
+ has_one :right_eye, class_name: "Eye", as: :eyeable
95
+ end
96
+
97
+ This would now need to be modeled as (with the appropriate migration):
98
+
99
+ class Eye
100
+ include Mongoid::Document
101
+ belongs_to :left_socket, class_name: "Face", inverse_of: :left_eye
102
+ belongs_to :right_socket, class_name: "Face", inverse_of: :right_eye
103
+ end
104
+
105
+ class Face
106
+ include Mongoid::Document
107
+ has_one :left_eye, class_name: "Eye", inverse_of: :left_socket
108
+ has_one :right_eye, class_name: "Eye", inverse_of: :right_socket
109
+ end
110
+
111
+ * \#3075 `update_attribute` now properly calls the setter method instead of
112
+ using `write_attribute`.
113
+
114
+ * \#3060 Allow atomically blocks to allow multiple calls of the same type.
115
+ (Brian Norton)
116
+
117
+ * \#3037 Model indexes are no longer stored in an `index_options` hash on the
118
+ model class. Instead, an array named `index_specifications` now exists on the
119
+ class which contains a list of `Indexable::Specification` objects. This is so
120
+ we could properly handle the case of indexes with the same keys but different
121
+ order.
122
+
123
+ * \#2991 The `timeless` feature has been removed, due to the fact with the current
124
+ overall design of Mongoid it would never be thread safe when accessed from the
125
+ class level, and has too many edge cases. Active Record's implementation of this
126
+ feature also suffers the same faults.
127
+
128
+ * \#2956 Caching on queries now only happens when `cache` is specifically
129
+ called. (Arthur Neves)
130
+
131
+ * \#2898 Dirty attribute methods now properly handle field aliases.
132
+ (Niels Ganser)
133
+
134
+ * \#2659 `Mongoid::Railtie` now properly uses only one initializer and
135
+ the name has changed to `mongoid.load-config`.
136
+
137
+ * \#2656 `rake db:reseed` is now `rake db:reset` (Arthur Neves)
138
+
139
+ * \#2648 `Boolean` becomes `Mongoid::Boolean` to avoid polluting the global
140
+ namespace with a commonly used class by other libraries.
141
+
142
+ * \#2603 Return values from setters are now always the set value, regardless
143
+ of calling the setter or using send.
144
+
145
+ * \#2563 The `allow_dynamic_fields` configuration option has been removed as
146
+ dynamic fields are now allowed on a per-model level. In order to allow a
147
+ model to use dynamic fields, simply include the module in each.
148
+ (Josh Martin)
149
+
150
+ class Band
151
+ include Mongoid::Document
152
+ include Mongoid::Attributes::Dynamic
153
+ end
154
+
155
+ * \#2497 Calling `to_json` no longer tampers with the return value from the
156
+ driver, and proper returns `{ "$oid" : object_id.to_s }` instead of just
157
+ the string representation previously.
158
+
159
+ * \#2433 `Mongoid::Paranoia` has been removed.
160
+
161
+ * \#2432 `Mongoid::Versioning` has been removed.
162
+
163
+ * \#2218 Creating or instantiating documents that have default scopes will now
164
+ apply the default scope to the document, if the scope is not complex.
165
+
166
+ * \#2200 Mass assignment security now mirrors Rails 4's behavior.
167
+
168
+ * `delete_all` and `destroy_all` no longer take a `:conditions` hash but
169
+ just the raw attributes.
170
+
171
+ * \#1344 Atomic updates can now be executed in an `atomically` block, which will
172
+ delay any atomic updates on the document the block was called on until the
173
+ block is complete.
174
+
175
+ Update calls can be executed as normal in the block:
176
+
177
+ document.atomically do
178
+ document.inc(likes: 10)
179
+ document.bit(members: { and: 10 })
180
+ document.set(name: "Photek")
181
+ end
182
+
183
+ The document is also yielded to the block:
184
+
185
+ document.atomically do |doc|
186
+ doc.inc(likes: 10)
187
+ doc.bit(members: { and: 10 })
188
+ doc.set(name: "Photek")
189
+ end
190
+
191
+ The atomic commands are have a fluid interface:
192
+
193
+ document.atomically do |doc|
194
+ doc.inc(likes: 10).bit(members: { and: 10 }).set(name: "Photek")
195
+ end
196
+
197
+ If the fluid interface is leveraged without the `atomically` block, the
198
+ operations will persist in individual calls. For example, the following
199
+ would hit the database 3 times without the block provided:
200
+
201
+ doc.inc(likes: 10).bit(members: { and: 10 }).set(name: "Photek")
202
+
203
+ The block is only good for 1 document at a time, so embedded and root
204
+ document updates cannot be mixed at this time.
205
+
206
+ ### New Features
207
+
208
+ * \#3155 Range field will persist the exclude_end when provided.
209
+ (Daniel Libanori)
210
+
211
+ * \#3146 Adding :overwrite field option, when it`s true, it wont check duplicates.
212
+ (Daniel Libanori)
213
+
214
+ * \#3002 Reloading the Rails console will also now clear Mongoid's identity map.
215
+
216
+ * \#2938 A configuration option `duplicate_fields_exception` has been added that
217
+ when set to `true` will raise an exception when defining a field that will
218
+ override an existing method. (Arthur Neves)
219
+
220
+ * \#2924 MongoDB 2.4 beta text search now has a DSL provided by Mongoid. Like
221
+ other queries, text searches are lazy evaluated, and available off the class
222
+ or criteria level.
223
+
224
+ Note that any 3rd party gem that provides a `text_search` method will now no
225
+ longer work with Mongoid, and will need to change its syntax. Examples:
226
+
227
+ Band.text_search("mode").project(name: 1).each do |doc|
228
+ # ...
229
+ end
230
+
231
+ Band.limit(10).text_search("phase").language("latin")
232
+ Band.where(:likes.gt => 1000).text_search("lucy")
233
+
234
+ * \#2855 Multiple extensions can now be supplied to relations. (Daniel Libanori)
235
+
236
+ ### Resolved Issues
237
+
238
+ * \#3242 Has_many relation must use the inverse foreign_key. (Arthur Neves)
239
+
240
+ * \#3197 Improvements in the calls to `aggregates` on root and embedded
241
+ collections. (Wojciech Piekutowski)
242
+
243
+ * \#3144/\#3219 Fixing name colission on @_children ivar. (Arthur Neves)
244
+
245
+ * \#3088 Range field can accept a hash, which could be the attribute from the db.
246
+ (Daniel Libanori)
247
+
248
+ * \#3116 Relations instance variables are now all prefixed with `_`.
249
+
250
+ * \#3093 Only flatten 1 level when atomically pushing arrays.
251
+
252
+ * \#3063 `Document#becomes` now properly sets base object on errors.
253
+ (Adam Ross Cohen)
254
+
255
+ * \#2903 Removed unused string `to_a` extension.
256
+
257
+ ## 3.1.5
258
+
259
+ ### Resolved Issues
260
+
261
+ * \#3231 Allow evolution of proxy documents to work in criteria.
262
+
263
+ * \#3203 Fixed `index: true` specification for polymorphic relations.
264
+
265
+ * \#3173 Fixed issues around many to many relations with custom primary keys.
266
+ (Bowen Sun)
267
+
268
+ * \#3159 Upserting now properly flags documents as persisted.
269
+
270
+ * \#3081 Criteria's `method_missing` now checks if an array responds to the provided
271
+ method before calling entries in order to not hit the database if a `NoMethodError`
272
+ was to get raised.
273
+
274
+ * \#3068 Fixed spec runs on non standard MongoDB ports if `MONGOID_SPEC_PORT` is
275
+ set.
276
+
277
+ * \#3047 Ensure `blank?` and `empty?` don't fall through method missing on criteria.
278
+
279
+ ## 3.1.4
280
+
281
+ ### Resolved Issues
282
+
283
+ * \#3044 Ensure enumerable targets match arrays in case statements.
284
+
285
+ * \#3034 `first_or_create` on criterion now properly passes the block to create
286
+ instead of calling after the document was created.
287
+
288
+ * \#3021 Removed `mongoid.yml` warning from initializer, this is now handled by
289
+ the session configuration options.
290
+
291
+ * \#3018 Uniqueness validator now properly serializes values in its check.
292
+ (Jerry Clinesmith)
293
+
294
+ * \#3011 Fixed aliased field support for uniqueness validation. (Johnny Shields)
295
+
296
+ * \#3008 Fixed subclasses not being able to inherit scopes properly when scope
297
+ is added post class load. (Mike Dillon)
298
+
299
+ * \#2991 `Document.timeless` now properly scopes to the instance and not thread.
300
+
301
+ * \#2980 Dynamic fields now properly handle in place editing of hashes and
302
+ arrays. (Matthew Widmann)
303
+
304
+ * \#2979 `pluck` no longer modifies the context in place. (Brian Goff)
305
+
306
+ * \#2970 Fixed counter cache to properly use the name of the relation if available
307
+ then the inverse class name second if not.
308
+
309
+ * \#2959 Nested attributes will now respect `autosave: false` if defined on the
310
+ relation.
311
+
312
+ * \#2944 Fixed uniqueness validation for localized fields when case insensitive
313
+ is true. (Vladimir Zhukov)
314
+
315
+ ## 3.1.3
316
+
317
+ ### Resolved Issues
318
+
319
+ * Dont duplicate embedded documents when saving after calling becomes method.
320
+ (Arthur Neves)
321
+
322
+ * \#2961 Reloading a mongoid.yml configuration now properly clears previously
323
+ configured sessions.
324
+
325
+ * \#2937 Counts can now take a `true` argument to factor in skip and limit.
326
+ (Arthur Neves)
327
+
328
+ * \#2921 Don't use type in identity map selection if inheritance is not
329
+ in play. (Arthur Neves)
330
+
331
+ * \#2893 Removed memoization of collection name and database name so lambdas
332
+ with `store_in` work properly when changing.
333
+
334
+ * \#2911 The `_destroy` attribute on 1-n relations when processing nested
335
+ attributes can now be a string or symbol when passed an array.
336
+
337
+ * \#2886 Fixed namespacing issue with Rails generators.
338
+
339
+ * \#2885 Fixed touch for aliased fields. (Niels Ganser)
340
+
341
+ * \#2883 Allow cyclic relations to not raise mixed relation errors.
342
+
343
+ * \#2867 `pluck` now properly handles aliased fields.
344
+
345
+ * \#2862 Autosaving no longer performs extra unnecessary queries.
346
+ (Arthur Neves)
347
+
348
+ ## 3.1.2
349
+
350
+ ### Resolved Issues
351
+
352
+ * \#2851 Fixed BigDecimal demongoization of NaN values. (nkem)
353
+
354
+ * \#2848 Fixed `touch` to work when usinng short timestamps. (Arthur Neves)
355
+
356
+ * \#2840 Fixed end-to-end `no_timeout` option handling.
357
+
358
+ * \#2826 Dynamic fields are now properly mongoized.
359
+
360
+ * \#2822 Marshal load of relations now properly reapplies extensions.
361
+
362
+ ## 3.1.1
363
+
364
+ ### Resolved Issues
365
+
366
+ * \#2839 Validations fixed to use the type cast value with the exception
367
+ of the numericality validator. (Lailson Bandeira)
368
+
369
+ * \#2838 `store_in` options now properly merge instead of override.
370
+ (Colin MacKenzie)
371
+
372
+ ## 3.1.0
373
+
374
+ ### New Features
375
+
376
+ * The minimum MongoDB requirement is now raised to 2.2, since we now
377
+ depend on the aggregation framework.
378
+
379
+ * The minimum Active Model and Active Support dependencies have been
380
+ raised to 3.2.
381
+
382
+ * \#2809 Relations can now specify a primary key to use instead of the
383
+ id on foreign keys.
384
+
385
+ class Person
386
+ include Mongoid::Document
387
+ field :username, type: String
388
+ has_many :cats, primary_key: "username"
389
+ end
390
+
391
+ class Cat
392
+ include Mongoid::Document
393
+ belongs_to :person, primary_key: "username"
394
+ end
395
+
396
+ * \#2804 $geoNear support has now been added to criteria.
397
+
398
+ Bar.where(:likes.gt => 1000).geo_near([ 52, 13 ])
399
+ Bar.geo_near([ 52, 13 ]).max_distance(0.5).spherical
400
+
401
+ * \#2799 Criteria#map can now accept a symbol of a field name as well as
402
+ a block to perform a more optimized `map`. (Gosha Arinich)
403
+
404
+ Band.where(:likes.gt => 1000).map(:name)
405
+
406
+ * \#2798 Aggregations (`sum`, `min`, `max`, `avg`) now use the
407
+ aggregation framework instead of map/reduce. (Gosha Arinich)
408
+
409
+ * \#2776 MongoDB 2.4.x new index types are now supported: "2dsphere",
410
+ "text", and "hashed". (Irakli Janiashvili)
411
+
412
+ * \#2767 $maxScan support from Origin is now supported. (Jonathan Hyman)
413
+
414
+ * \#2701 Cleanup up extra excessive database queries with 1-1 relations.
415
+
416
+ * \#2693 Custom collection names can be passed to the model generator.
417
+ (Subhash Bhushan)
418
+
419
+ rails g model band --collection=artists
420
+
421
+ * \#2688 `Model.create` and `Model.create!` now can take an array of
422
+ attributes hashes to create multiple documents at once. If an array
423
+ of attributes is provided then an array of documents is returned.
424
+
425
+ Band.create([{ name: "Tool" }, { name: "Placebo" }])
426
+ Band.create!([{ name: "Tool" }, { name: "Placebo" }])
427
+
428
+ * \#2670 Unsetting fields now accepts multiple fields instead of only 1.
429
+ (Arthur Neves)
430
+
431
+ band.unset(:name, :founded)
432
+ Band.where(name: "Placebo").unset(:members, :origin)
433
+
434
+ * \#2669 Passing a block to `Criteria#new` now properly sends the
435
+ block through to the model's contructor. (Arthur Neves)
436
+
437
+ * \#2667 `exists?` no longer hits the database in cases where we have
438
+ the necessary information in memory.
439
+
440
+ * \#2665 Mongoid now supports a counter cache for `belongs_to`
441
+ relations. (Arthur Neves)
442
+
443
+ class Band
444
+ include Mongoid::Document
445
+ belongs_to :label, counter_cache: "b_count"
446
+ end
447
+
448
+ class Album
449
+ include Mongoid::Document
450
+ belongs_to :band, counter_cache: true
451
+ end
452
+
453
+ * \#2662 Embedded documents that have `belongs_to` relations may now
454
+ eager load them.
455
+
456
+ * \#2657 Logger getter and setter convenience methods have been
457
+ added to the `Config` module. (Arthur Neves)
458
+
459
+ * \#2615 Index options can now take a specific database name if the
460
+ indexes are only to exist in a database other than the default.
461
+
462
+ class Band
463
+ include Mongoid::Document
464
+ index name: 1, { database: "another_db" }
465
+ end
466
+
467
+ * \#2613 Procs can now be provided as values to `store_in`:
468
+
469
+ class Band
470
+ include Mongoid::Document
471
+ store_in database: ->{ Thread.current[:database] }
472
+ end
473
+
474
+ * \#2609 Pass through batch_size option to query. (Martin Mauch)
475
+
476
+ * \#2555 Passing hashes to `find` when the documents id is of type hash
477
+ now properly works. (Szymon Kurcab)
478
+
479
+ * \#2545 The `$` positional operator is used for update selectors on
480
+ embedded documents that are nested 1 level deep, when appropriate.
481
+
482
+ * \#2539 `Mongoid.models` now tracks all models in the application for more
483
+ accurate determination of models for things such as indexing rake tasks.
484
+ (Ara Howard)
485
+
486
+ * \#2525 Added the ability to have short timestamped fields with aliases. This
487
+ sets timestamp fields as `c_at` and `u_at` that are also aliased as
488
+ `created_at` and `updated_at` for convenience. (Rodrigo Saito)
489
+
490
+ class Band
491
+ include Mongoid::Document
492
+ include Mongoid::Timestamps::Short # For c_at and u_at.
493
+ end
494
+
495
+ class Band
496
+ include Mongoid::Document
497
+ include Mongoid::Timestamps::Created::Short # For c_at only.
498
+ end
499
+
500
+ class Band
501
+ include Mongoid::Document
502
+ include Mongoid::Timestamps::Updated::Short # For u_at only.
503
+ end
504
+
505
+ * \#2465 Documents now have an `attribute_before_type_cast` for proper
506
+ handling of validations. (Gerad Suyderhoud)
507
+
508
+ * \#2443 `expire_after_seconds` is now a valid index option
509
+ (http://docs.mongodb.org/manual/core/indexes/#ttl-indexes,
510
+ http://docs.mongodb.org/manual/tutorial/expire-data/).
511
+
512
+ class Event
513
+ include Mongoid::Document
514
+ field :created_at, type: DateTime
515
+ index({ created_at: 1 }, { expire_after_seconds: 3600 })
516
+ end
517
+
518
+ * \#2373 Relations with the `touch: true` option will now be automatically
519
+ touched when the child document is created or destroyed.
520
+
521
+ * Added `Document.first_or_create!` and `Criteria#first_or_create!`. This
522
+ raises a validations error if creation fails validation.
523
+
524
+ Band.where(name: "Depeche Mode").first_or_create!
525
+ Band.where(name: "Tool").first_or_create!(active: true)
526
+
527
+ * Added `Document.first_or_initialize` and `Criteria#first_or_initialize`.
528
+ This is the same as `first_or_create` but initializes a new (unpersisted)
529
+ document if none is found.
530
+
531
+ Band.where(name: "Depeche Mode").first_or_initialize
532
+ Band.where(name: "Tool").first_or_initialize(active: true)
533
+
534
+ * Added `Model.pluck` and `Criteria#pluck` similar to Active Record's, which
535
+ returns an array of values for the provided field. (Jason Lee)
536
+
537
+ Band.where(name: "Depeche Mode").pluck(:_id)
538
+ Band.where(name: "Tool").pluck(:likes)
539
+
540
+ * \#2324 Embeds many relations now properly handle `delete_if`.
541
+
542
+ * \#2317 Added `Document.first_or_create` and `Criteria#first_or_create`.
543
+ This will return the first matching document or create one with additional
544
+ attributes if one does not exist. (incorvia)
545
+
546
+ Band.where(name: "Depeche Mode").first_or_create
547
+ Band.where(name: "Tool").first_or_create(active: true)
548
+
549
+ * \#2292 Added `Model.each_with_index`.
550
+
551
+ * \#2285 `Config.load_configuration` is now public for those who want to instantiate
552
+ settings directly from a hash.
553
+
554
+ * \#2275 Added rake task `db:mongoid:purge` that will drop all collections with
555
+ the exception of the system collections in the default database.
556
+
557
+ * \#2257 `after_find` callbacks have been added for when documents are returned
558
+ from the database.
559
+
560
+ class Band
561
+ include Mongoid::Document
562
+
563
+ after_find do |doc|
564
+ # Some logic here.
565
+ end
566
+ end
567
+
568
+ * \#2223 Allow to find documents by javascript with parameters that are
569
+ protected from javascript injection via `Model.for_js`.
570
+
571
+ Band.for_js("this.name = param", param: "Tool")
572
+ Band.where(:likes.gt => 1000).for_js("this.likes < this.follows")
573
+
574
+ * \#2197 When providing session configuration with no ports, Mongoid will now
575
+ default these to 27017.
576
+
577
+ * \#2180 1-n and n-n relations now support before/after add/remove callbacks.
578
+ (Rodrigo Saito)
579
+
580
+ class Band
581
+ include Mongoid::Document
582
+
583
+ embeds_many :albums, after_add: :notify_labels
584
+ has_many :followers, before_remove: ->(band, follower){ notify_unfollow(follower) }
585
+ end
586
+
587
+ * \#2157 `Criteria#update` and `Criteria#update_all` now serialize values
588
+ according to their field type, if a field is defined.
589
+
590
+ * \#2022 Custom callbacks can now register themselves for use with observers
591
+ by using the `observable` macro.
592
+
593
+ class Band
594
+ include Mongoid::Document
595
+
596
+ define_model_callbacks :notification
597
+ observable :notification
598
+ end
599
+
600
+ class BandObserver < Mongoid::Observer
601
+
602
+ def before_notification(band)
603
+ #...
604
+ end
605
+
606
+ def after_notification(band)
607
+ #...
608
+ end
609
+ end
610
+
611
+ * \#1766 Many to many relations will not touch the database if the foreign key
612
+ is an empty array.
613
+
614
+ * \#1564 Many to many foreign keys now have the default set lazily only if the
615
+ relation has been accessed. This avoids storing empty arrays if the relation
616
+ has not been touched.
617
+
618
+ ### Resolved Issues
619
+
620
+ * \#2730 Calling sort on a context properly updates the context's criteria.
621
+ (Arthur Neves)
622
+
623
+ * \#2719 `distinct` is now available at the class level.
624
+
625
+ Band.distinct(:name)
626
+
627
+ * \#2714 Overriding sessions when the new session has a different database will
628
+ now properly switch the database at runtime as well.
629
+
630
+ * \#2697 Eager loading fixed when including multiple models that inherit from
631
+ the same class. (Kirill Lazarev)
632
+
633
+ * \#2664 In memory sorting of embedded documents now properly works when
634
+ multiple fields are provided. (Neer Friedman)
635
+
636
+ ## 3.0.24
637
+
638
+ ### Resolved Issues
639
+
640
+ * \#2879 `remove_attribute` on new documents no longer creates an unnecessary
641
+ $unset operation.
642
+
643
+ ## 3.0.23
644
+
645
+ ### Resolved Issues
646
+
647
+ * \#2851 Fixed BigDecimal demongoization of NaN values. (nkem)
648
+
649
+ * \#2841 Calling `delete_all` or `destroy_all` on an embeds many when in the
650
+ middle of a parent update will now properly execute the deletion.
651
+ (Arthur Neves)
652
+
653
+ * \#2835 Fixed clearing of persistence options in uniqueness validator.
654
+
655
+ * \#2826 Dynamic fields are now properly mongoized.
656
+
657
+ * \#2822 Marshal load of relations now properly reapplies extensions.
658
+
659
+ * \#2821 Autosaved relations should be duped in inheriting classes.
660
+
661
+ ## 3.0.22
662
+
663
+ ### Resolved Issues
664
+
665
+ * \#2812 Fixed criteria on many to many relations when the base document is
666
+ destroyed and the foreign key has not yet been lazy evaluated.
667
+
668
+ * \#2796 Don't cascade changes on has_many relations when assigning with
669
+ a delete.
670
+
671
+ * \#2795 Fix precision on time conversions. (Tom de Bruijn)
672
+
673
+ * \#2794 Don't autobuild when reading a relation for validation.
674
+
675
+ * \#2790 `becomes` now copies embedded documents even if they were protected
676
+ by mass assignment.
677
+
678
+ * \#2787 Allow `becomes` to replace the document in the identity map.
679
+
680
+ * \#2786 Fixed regressed cascading callbacks on destroy not firing.
681
+
682
+ * \#2784 Fixed uniqueness validation properly getting added to subclasses.
683
+ (Takeshi Akima)
684
+
685
+ ## 3.0.21
686
+
687
+ ### Resolved Issues
688
+
689
+ * \#2781 / * \#2777 - Fixed issue with serialization of `DateTime` that was
690
+ only present in Rails environments.
691
+
692
+ ## 3.0.20
693
+
694
+ ### Resolved Issues
695
+
696
+ * \#2774 Ensure validations macros for uniqueness, presence, and associated
697
+ are also available at the instance level.
698
+
699
+ * \#2772 Localized fields are now properly handled when cloning a document.
700
+
701
+ * \#2758 `Mongoid.create_indexes` does not fail when cannot constantize class.
702
+ (Arthur Neves)
703
+
704
+ * \#2743 Persistence options are no longer cleared when loading revisions.
705
+ (Arthur Neves)
706
+
707
+ * \#2741 Fix time mongoization usec rounding errors on MRI and JRuby.
708
+
709
+ * \#2740 Support integer keys in hash fields when using `read_attribute` with
710
+ dot notation.
711
+
712
+ * \#2739 Ensure integer deserialization properly casts to integers.
713
+
714
+ * \#2733 Many to many relations with `inverse_of: nil` do not persist the
715
+ inverse relation on `<<` or `push` if the document is already persisted.
716
+
717
+ * \#2705 Fixed logic around when children can be added to the cascading
718
+ callbacks list.
719
+
720
+ ## 3.0.19
721
+
722
+ ### Resolved Issues
723
+
724
+ * Released to revert the changes in \#2703.
725
+
726
+ ## 3.0.18
727
+
728
+ ### Resolved Issues
729
+
730
+ * \#2707 Calling `find_or_create_by` or `find_by_initialize_by` off a relation
731
+ with a chained criteria or scope now properly keeps the relations intact on
732
+ the new or found document.
733
+
734
+ * \#2699 Resetting a field now removes the name from the changed attributes
735
+ list. (Subhash Bhushan)
736
+
737
+ * \#2683 Aliased fields are now supported when executing atomic operations from
738
+ criteria. (Arthur Neves)
739
+
740
+ * \#2678 Calling `Criteria#sum` with no matching documents returns `0` instead
741
+ of `nil`.
742
+
743
+ * \#2671 Matchers now correctly handle symbol keys. (Jonathan Hyman)
744
+
745
+ ## 3.0.17
746
+
747
+ ### Resolved Issues
748
+
749
+ * \#2686 Fixed the broken Moped dependency - Moped now must be at least at
750
+ version 1.2.0.
751
+
752
+ ## 3.0.16
753
+
754
+ ### Resolved Issues
755
+
756
+ * \#2661 Implement instance level `model_name` for documents.
757
+
758
+ * \#2651 Ensure `Criteria#type` works properly with both symbol and string
759
+ keys in the selector.
760
+
761
+ * \#2647 Ensure `deleted?` and `destroyed?` on paranoid documents return the
762
+ same value.
763
+
764
+ * \#2646 Set unloaded doc in memory on enumerable targets before yielding to
765
+ the block.
766
+
767
+ * \#2645 Take caching into consideration when asking for counts.
768
+ (Arthur Nogueira Neves)
769
+
770
+ * \#2642 Don't batch push empty arrays on embedded documents. (Laszlo Bacsi)
771
+
772
+ * \#2639 Avoid extra unnecesary queries on new records when building relations
773
+ off of them.
774
+
775
+ * \#2638 When a criteria is eager loading, calling `first` or `last` then
776
+ iterating the entire results properly eager loads the full request.
777
+
778
+ * \#2618 Validating uniqueness now always uses string consistency by default.
779
+
780
+ * \#2564 Fixed infinite recursion for cases where a relation getter was
781
+ overridden and called the setter from that method.
782
+
783
+ * \#2554 Ensure `unscoped` on an `embeds_many` does not include documents
784
+ flagged for destruction.
785
+
786
+ ## 3.0.15
787
+
788
+ ### Resolved Issues
789
+
790
+ * \#2630 Fix cascading when the metadata exists but no cascade defined.
791
+
792
+ * \#2625 Fix `Marshal.dump` and `Marshal.load` of proxies and criteria
793
+ objects.
794
+
795
+ * \#2619 Fixed the classes returned by `observed_classes` on an observer
796
+ when it is observing custom models.
797
+
798
+ * \#2612 `DocumentNotFound` errors now expose the class in the error
799
+ instance.
800
+
801
+ * \#2610 Ensure calling `first` after a `last` that had sorting options resets
802
+ the sort.
803
+
804
+ * \#2604 Check pulls and pushes for conflicting updates. (Lucas Souza)
805
+
806
+ * \#2600 Instantiate the proper class type for attributes when using
807
+ multi parameter attributes. (xxswingxx)
808
+
809
+ * \#2598 Fixed sorting on localized fields with embedded docs.
810
+
811
+ * \#2588 Block defining methods for dynamic attributes that would be invalid
812
+ ruby methods. (Matt Sanford)
813
+
814
+ * \#2587 Fix method clash with `belongs_to` proxies when resetting relation
815
+ unloaded criteria.
816
+
817
+ * \#2585 Ensure session configuration options get passed to Moped as symbols.
818
+
819
+ * \#2584 Allow map/reduce to operate on secondaries if output is set to `inline`.
820
+
821
+ * \#2582 Ensure `nil` session override can never cause to access a session with
822
+ name `nil`.
823
+
824
+ * \#2581 Use strong consistency when reloading documents. (Mark Kremer)
825
+
826
+ ## 3.0.14
827
+
828
+ ### Resolved Issues
829
+
830
+ * \#2575 Prevent end of month times from rounding up since floats are not
831
+ precise enough to handle usec. (Steve Valaitis)
832
+
833
+ * \#2573 Don't use i18n for inspection messages.
834
+
835
+ * \#2571 Remove blank error message from locales. (Jordan Elver)
836
+
837
+ * \#2568 Fix uniqueness validation for lacalized fields when a scope is also
838
+ provided.
839
+
840
+ * \#2552 Ensure `InvalidPath` errors are raised when embedded documents try to
841
+ get paths from a root selector.
842
+
843
+ ## 3.0.13
844
+
845
+ ### Resolved Issues
846
+
847
+ * \#2548 Fix error when generating config file with a fresh app with Unicorn in
848
+ the gemset.
849
+
850
+ ## 3.0.12
851
+
852
+ ### Resolved Issues
853
+
854
+ * \#2542 Allow embedded documents using `store_as` to properly alias in
855
+ criteria.
856
+
857
+ * \#2541 Ensure that the type change is correct when upcasting/downcasting a
858
+ document via `Document#becomes` (Łukasz Bandzarewicz)
859
+
860
+ * \#2529 Fields on subclasses that override fields in the parent where both have
861
+ defaults with procs now properly override the default in the subclass.
862
+
863
+ * \#2528 Aliased fields need to be duped when subclassing.
864
+
865
+ * \#2527 Ensure removal of docs in a `has_many` does a multi update when setting
866
+ to an empty array.
867
+
868
+ ## 3.0.11
869
+
870
+ ### Resolved Issues
871
+
872
+ * \#2522 Fixed `Criteria#with` to return the criteria and not the class.
873
+
874
+ * \#2518 Fix unit of work call for the identity map when using Passenger.
875
+
876
+ * \#2512 Ensure nested attributes destroy works with the delayed destroys
877
+ introduced in 3.0.10 when multiple levels deep.
878
+
879
+ * \#2509 Don't hit identity map an extra time when the returned value is an
880
+ empty hash. (Douwe Maan)
881
+
882
+ ## 3.0.10
883
+
884
+ ### Resolved Issues
885
+
886
+ * \#2507 Ensure no extra db hits when eager loading has a mix of parents
887
+ with and without docs. (Douwe Maan)
888
+
889
+ * \#2505 Ensure `update` and `update_all` from criteria properly handle
890
+ aliased fields. (Dmitry Krasnoukhov)
891
+
892
+ * \#2504 `Model#becomes` properly keeps the same id.
893
+
894
+ * \#2498 Criteria now properly pass provided blocks though `method_missing`.
895
+
896
+ * \#2496 Embedded documents that were previously stored without ids now
897
+ properly update and get assigned ids from within Mongoid.
898
+
899
+ * \#2494 All explicit atomic operations now properly respect aliased fields.
900
+
901
+ * \#2493 Use `Class#name` instead of `Class#model_name` when setting
902
+ polymorphic types in case `model_name` has been overridden.
903
+
904
+ * \#2491 Removed unnecessary merge call in cascadable children.
905
+
906
+ * \#2485 Removing indexes now always uses strong consistency.
907
+
908
+ * \#2483 Versioning now handles localized fields. (Lawrence Curtis)
909
+
910
+ * \#2482 Store find parameters in the `DocumentNotFound` error.
911
+
912
+ * \#2481 Map/reduce aggregations now properly handle Mongo's batching of
913
+ reduce jobs in groups of 100 with the state being passed through on the
914
+ count.
915
+
916
+ * \#2476 Handle skip and limit outside of range on embeds_many relations
917
+ gracefully.
918
+
919
+ * \#2474 Correctly detach 1-1 relations when the child is not yet loaded.
920
+ (Kostyantyn Stepanyuk)
921
+
922
+ * \#2451 `relation.deleted` on embedded paranoid documents now works properly
923
+ again.
924
+
925
+ * \#2472 Ensure `update_all` on embedded relations works properly when nothing
926
+ is actually going to be updated.
927
+
928
+ * \#2469 Nullified documents on relations are now able to be re-added with the
929
+ same in memory instance.
930
+
931
+ * \#2454 `Model#as_document` properly allows changes from having a relation to
932
+ the relation being removed. (James Almond)
933
+
934
+ * \#2445 Mongoid middleware now properly supports both normal and streamed
935
+ responses and properly clears the identity map for either.
936
+
937
+ * \#2367 Embedded documents that are to be deleted via nested attributes no
938
+ longer become immediately removed from the relation in case the parent
939
+ validation fails. Instead, they get flagged for destruction and then the
940
+ removal occurs upon the parent passing validation and going to persist.
941
+
942
+ Note this is a behaviour change, but since the API does not change and
943
+ the previous behaviour was incorrect and did not match AR this was able
944
+ to go into a point release.
945
+
946
+ ## 3.0.9
947
+
948
+ ### Resolved Issues
949
+
950
+ * \#2463 Fixed the broken `rails g mongoid:config` from a fresh repo.
951
+
952
+ * \#2456 The descendants cache is now reset when the document is inherited
953
+ again. (Kostyantyn Stepanyuk)
954
+
955
+ * \#2453 `Model#write_attribute` now properly works with aliased fields.
956
+ (Campbell Allen)
957
+
958
+ * \#2444 Removed extra dirty methods creation call. (Kostyantyn Stepanyuk)
959
+
960
+ * \#2440/\#2435 Pass mass assignment options down to children when setting via
961
+ nested attributes or embedded documents.
962
+
963
+ * \#2439 Fixed memory leak in threaded selection of returned fields.
964
+ (Tim Olsen)
965
+
966
+ * mongoid/moped\#82 Aliased fields now work with `Criteria#distinct`.
967
+
968
+ * \#2423 Fixed embedded document's `update_all` to perform the correct $set
969
+ when using off a criteria.
970
+
971
+ * \#2414 Index definitions now respect aliased fields.
972
+
973
+ * \#2413 Enumerable targets now properly return enumerators when no blocks
974
+ are provided. (Andrew Smith)
975
+
976
+ * \#2411 BigDecimal fields are properly stored as strings when mongoizing
977
+ integers and floats.
978
+
979
+ * \#2409 Don't warn about missing mongoid.yml if configured programatically.
980
+
981
+ * \#2403 Return false on `update_all` of an embeds many with no documents.
982
+
983
+ * \#2401 Bring back the ability to merge a criteria with a hash.
984
+
985
+ * \#2399 Reject blank id values on has_many `Model#object_ids=`.
986
+ (Tiago Rafael Godinho)
987
+
988
+ * \#2393 Ensure `inverse_of` is respected when using polymorphic relations.
989
+
990
+ * \#2388 Map/reduce properly uses `sort` instead of `orderby` in the execution
991
+ of the command. (Alex Tsibulya)
992
+
993
+ * \#2386 Allow geo haystack and bits parameters in indexes. (Bradley Rees)
994
+
995
+ * \#2380 `Model#becomes` now properly copies over dirty attributes.
996
+
997
+ * \#2331 Don't double push child documents when extra saves are called in an
998
+ after_create callback.
999
+
1000
+ ## 3.0.8 (Yanked)
1001
+
1002
+ ## 3.0.6
1003
+
1004
+ ### Resolved Issues
1005
+
1006
+ * \#2375 Uniqueness validation scoping now works with aliased fields.
1007
+
1008
+ * \#2372 Ensure that all atomic operations mongoize values before executing.
1009
+
1010
+ * \#2370 Paranoid documents now properly don't get deleted when using
1011
+ `dependent: :restrict` and an exception is raised.
1012
+
1013
+ * \#2365 Don't do anything when trying to replace an embeds_one with the same
1014
+ document.
1015
+
1016
+ * \#2362 Don't store inverse of field values in the database when they are not
1017
+ needed. (When there is not more than one polymorphic parent defined on the
1018
+ same class).
1019
+
1020
+ * \#2360 Cloning documents should ignore mass assignment protection rules.
1021
+
1022
+ * \#2356 When limiting fields returned in queries via `only` ensure that the
1023
+ limitation is scoped to the model.
1024
+
1025
+ * \#2353 Allow `update_attribute` to properly handle aliased fields.
1026
+
1027
+ * \#2348 Conversion of strings to times should raise an arugment error if the
1028
+ string is invalid. (Campbell Allen)
1029
+
1030
+ * \#2346 Ensure `belongs_to` relations are evolvable when passed the proxy and
1031
+ not the document.
1032
+
1033
+ * \#2334 Fixed aggregation map/reduce when fields sometimes do not exist.
1034
+ (James McKinney)
1035
+
1036
+ * \#2330 Fixed inconsistency of #size and #length on criteria when the documents
1037
+ have been iterated over with a limit applied.
1038
+
1039
+ * \#2328 Ensure ordering is applied on all relation criteria if defined.
1040
+
1041
+ * \#2327 Don't execute callbacks from base document if the document cannot execute
1042
+ them.
1043
+
1044
+ * \#2318 Ensure setting any numeric on a Float field actually sets it as a float,
1045
+ even if the number provided is an integer.
1046
+
1047
+ ## 3.0.5
1048
+
1049
+ ### Resolved Issues
1050
+
1051
+ * \#2313 Fixed deserialization of `nil` `TimeWithZone` fields. (nagachika)
1052
+
1053
+ * \#2311 `Document#changes` no longer returns `nil` values for Array and Hash
1054
+ fields that were only accessed and didn't actually change. Regression from 2.4.x.
1055
+
1056
+ * \#2310 Setting a many to many duplicate successively in memory no longer clears
1057
+ the inverse foreign keys.
1058
+
1059
+ * \#2309 Allow embeds_one relations to be set with hashes more than just the
1060
+ initial set.
1061
+
1062
+ * \#2308 Ensure documents retrieved via `#find` on `has_many` and
1063
+ `has_and_belongs_to_many` relations are kept in memory.
1064
+
1065
+ * \#2304 Default scopes now properly merge instead of overwrite when more
1066
+ than one is defined as per expectations with AR. (Kirill Maksimov)
1067
+
1068
+ * \#2300 Ensure reloading refreshes the document in the identity map.
1069
+
1070
+ * \#2298 Protect against many to many relations pulling a null set of ids.
1071
+ (Jonathan Hyman)
1072
+
1073
+ * \#2291 Fixed touch operations only to update the timestamp and the optional
1074
+ field, no matter what the other changes on the document are.
1075
+
1076
+ * \#1091 Allow presence validation to pass if the value is `false`.
1077
+
1078
+ ## 3.0.4
1079
+
1080
+ ### Resolved Issues
1081
+
1082
+ * \#2280 Fix synchronization of many-to-many relations when an ordering default
1083
+ scope exists on either side of the association.
1084
+
1085
+ * \#2278 `Criteria#update` now properly updates only the first matching document,
1086
+ where `Criteria#update_all` will update all matching documents. (no flag vs multi).
1087
+
1088
+ * \#2274 When loading models, warn if error is raised but continue processing.
1089
+
1090
+ * \#2272 Don't wipe selectors or options when removing the default scope for
1091
+ actual nil values. Must check if key exists as well.
1092
+
1093
+ * \#2266 Restored paranoid documents are no longer flagged as destroyed.
1094
+ (Mario Uher)
1095
+
1096
+ * \#2263 Ensure casting of non object id foreign keys on many to many relations
1097
+ happens in the initial set, not at validation time.
1098
+
1099
+ ## 3.0.3
1100
+
1101
+ ### Resolved Issues
1102
+
1103
+ * \#2259 Ensure subclassed documents can not be pulled from the identity map
1104
+ via an id of another document in the same collection with a parent or
1105
+ sibeling type.
1106
+
1107
+ * \#2254 $inc operations no longer convert all values to floats.
1108
+
1109
+ * \#2252 Don't fire autosave when before callbacks have terminated.
1110
+
1111
+ * \#2248 Improved the performance of `exists?` on criteria and relations.
1112
+ (Jonathan Hyman)
1113
+
1114
+ ## 3.0.2
1115
+
1116
+ ### Resolved Issues
1117
+
1118
+ * \#2244 Get rid of id mass assignment warnings in nested attributes.
1119
+
1120
+ * \#2242 Fix eager loading not to load all documents when calling first or
1121
+ last.
1122
+
1123
+ * \#2241 Map/reduce operations now always use strong consistency since they
1124
+ have the potential to write to collections, most of the time.
1125
+
1126
+ * \#2238 Ensure n-n foreign key fields are flagged as resizable to prevent
1127
+ `nil` -> `[]` changes when using `#only` and updating.
1128
+
1129
+ * \#2236 Keep the instance of the document in the validations exception
1130
+ accessible via `document` or `record`.
1131
+
1132
+ * \#2234 Ensure validations when document is getting persisted with custom
1133
+ options work properly with custom options, and do not clear them out if
1134
+ validation passes.
1135
+
1136
+ * \#2224 `Model#inc` now accepts `BigDecimal` values.
1137
+
1138
+ * \#2216 Fixed assignment of metadata on embeds one relations when setting
1139
+ multiple times in a row.
1140
+
1141
+ * \#2212 Ensure errors are cleared after a save with `validate: false` in all
1142
+ situations.
1143
+
1144
+ * \#2207 When eager loading ids the query must be duped to avoid multiple
1145
+ iteration problems not getting the required fields.
1146
+
1147
+ * \#2204 Raise an `InvalidIncludes` error when passing arguments to
1148
+ `Criteria.includes` that are invalid (not relations, or more than 1 level.)
1149
+
1150
+ * \#2203 Map/Reduce now works properly in conjunction with `Model#with`.
1151
+
1152
+ Band.
1153
+ with(session: "secondary").
1154
+ where(:likes.gt => 100).
1155
+ map_reduce(map, reduce).
1156
+ out(inline: 1)
1157
+
1158
+ * \#2199 Autosave false is now respected when automatically adding
1159
+ presence validation. (John Nishinaga)
1160
+
1161
+ ## 3.0.1
1162
+
1163
+ ### Resolved Issues
1164
+
1165
+ * \#2191 Ensure proper visibility (private) for error message generation
1166
+ methods.
1167
+
1168
+ * \#2187 Ensure all levels of nested documents are serialized in json.
1169
+
1170
+ * \#2184 Allow names of relations that conflict with ruby core kernel
1171
+ methods to pass existence checks.
1172
+
1173
+ * \#2181 Ensure `.first` criteria sort by ascending ids, if no other
1174
+ sorting criteria was provided.
1175
+
1176
+ ## 3.0.0
1177
+
1178
+ ### New Features
1179
+
1180
+ * \#2151 When asking for metadata before persistence, Mongoid will now
1181
+ raise a `Mongoid::Errors::NoMetadata` error if the metadata is not
1182
+ present.
1183
+
1184
+ * \#2147 `Model#becomes` now copies over the embedded documents.
1185
+
1186
+ * A new callback has been introduced: `upsert`, which runs when calling
1187
+ `document.upsert` since Mongoid does not know if the document is to be
1188
+ treated as new or persisted. With this come the model callbacks:
1189
+
1190
+ before_upsert
1191
+ after_upsert
1192
+ around_upsert
1193
+
1194
+ * \#2080/\#2087 The database or session that Mongoid persists to can now be
1195
+ overridden on a global level for cases where `Model#with` is not a viable
1196
+ option.
1197
+
1198
+ Mongoid.override_database(:secondary)
1199
+ Mongoid.override_session(:secondary)
1200
+
1201
+ Band.create(name: "Placebo") #=> Persists to secondary.
1202
+ band.albums.create #=> Persists to secondary.
1203
+
1204
+ Note that this option is global and overrides for all models on the current
1205
+ thread. It is the developer's responsibility to remember to set this back
1206
+ to nil if you no longer want the override to happen.
1207
+
1208
+ Mongoid.override_database(nil)
1209
+ Mongoid.override_session(nil)
1210
+
1211
+ * \#1989 Criteria `count`, `size` and `length` now behave as Active Record
1212
+ with regards to database access.
1213
+
1214
+ `Criteria#count` will always hit the database to get the count.
1215
+
1216
+ `Criteria#length` and `Criteria#size` will hit the database once if the
1217
+ criteria has not been loaded, and subsequent calls will return the
1218
+ cached value.
1219
+
1220
+ If the criteria has been iterated over or loaded, `length` and `size`
1221
+ will never hit the db.
1222
+
1223
+ * \#1976 Eager loading no longer produces queries when the base query returns
1224
+ zero results.
1225
+
1226
+ * `Model.find_by` now accepts a block and will yield to the found document if
1227
+ it is not nil.
1228
+
1229
+ Band.find_by(name: "Depeche Mode") do |band|
1230
+ band.likes = 100
1231
+ end
1232
+
1233
+ * \#1958/\#1798 Documents and `belongs_to` relations now support touch.
1234
+
1235
+ class Band
1236
+ include Mongoid::Document
1237
+ include Mongoid::Timestamps::Updated
1238
+ belongs_to :label, touch: true
1239
+ end
1240
+
1241
+ Update the document's updated_at timestamp to the current time. This
1242
+ will also update any touchable relation's timestamp as well.
1243
+
1244
+ Band.first.touch
1245
+
1246
+ Update a specific time field along with the udpated_at.
1247
+
1248
+ Band.first.touch(:founded)
1249
+
1250
+ This fires no validations or callbacks.
1251
+
1252
+ * Mongoid now supports MongoDB's $findAndModify command.
1253
+
1254
+ Band.find_and_modify("$inc" => { likes: 1 })
1255
+
1256
+ Band.desc(:name).only(:name).find_and_modify(
1257
+ { "$inc" => { likes: 1 }}, new: true
1258
+ )
1259
+
1260
+ * \#1906 Mongoid will retrieve documents from the identity map when
1261
+ providing multiple ids to find. (Hans Hasselberg)
1262
+
1263
+ * \#1903 Mongoid raises an error if provided a javascript expression
1264
+ to a where clause on an embedded collection. (Sebastien Azimi)
1265
+
1266
+ * Aggregations now adhere to both a Mongoid API and their enumerable
1267
+ counterparts where applicable.
1268
+
1269
+ Band.min(:likes)
1270
+ Band.min do |a, b|
1271
+ a.likes <=> b.likes
1272
+ end
1273
+
1274
+ Band.max(:likes)
1275
+ Band.max do |a, b|
1276
+ a.likes <=> b.likes
1277
+ end
1278
+
1279
+ Note that when providing a field name and no block, a single numeric
1280
+ value will be returned, but when providing a block, a document will
1281
+ be returned which has the min/max value. This is since Ruby's
1282
+ Enumerable API dictates when providing a block, the matching element
1283
+ is returned.
1284
+
1285
+ When providing a block, all documents will be loaded into memory.
1286
+ When providing a symbol, the execution is handled via map/reduce on
1287
+ the server.
1288
+
1289
+ * A kitchen sink aggregation method is now provided, to get everything in
1290
+ in a single call for a field.
1291
+
1292
+ Band.aggregates(:likes)
1293
+ # =>
1294
+ # {
1295
+ # "count" => 2.0,
1296
+ # "max" => 1000.0,
1297
+ # "min" => 500.0,
1298
+ # "sum" => 1500.0,
1299
+ # "avg" => 750.0
1300
+ # }
1301
+
1302
+ * A DSL off the criteria API is now provided for map/reduce operations
1303
+ as a convenience.
1304
+
1305
+ Band.where(name: "Tool").map_reduce(map, reduce).out(inline: 1)
1306
+ Band.map_reduce(map, reduce).out(replace: "coll-name")
1307
+ Band.map_reduce(map, reduce).out(inline: 1).finalize(finalize)
1308
+
1309
+ * Mongoid now uses Origin for its Criteria API. See the Origin repo
1310
+ and API docs for the documentation.
1311
+
1312
+ * \#1861 Mongoid now raises an `AmbiguousRelationship` error when it
1313
+ cannot determine the inverse of a relation and there are multiple
1314
+ potential candidates. (Hans Hasselberg)
1315
+
1316
+ * You can now perform an explain directly from criteria.
1317
+
1318
+ Band.where(name: "Depeche Mode").explain
1319
+
1320
+ * \#1856 Push on one to many relations can now be chained.
1321
+
1322
+ band.albums.push(undertow).push(aenima)
1323
+
1324
+ * \#1842 MultiParameterAttributes now supported aliased fields.
1325
+ (Anton Orel)
1326
+
1327
+ * \#1833 If an embedded document is attempted to be saved with no
1328
+ parent defined, Mongoid now will raise a `Mongoid::Errors::NoParent`
1329
+ exception.
1330
+
1331
+ * Added an ORM-agnostic way to get the field names
1332
+
1333
+ class Band
1334
+ include Mongoid::Document
1335
+ field :name, type: String
1336
+ end
1337
+
1338
+ Band.attribute_names
1339
+
1340
+ * \#1831 `find_or_create_by` on relations now takes mass assignment
1341
+ and type options. (Tatsuya Ono)
1342
+
1343
+ class Band
1344
+ include Mongoid::Document
1345
+ embeds_many :albums
1346
+ end
1347
+
1348
+ band.albums.find_or_create_by({ name: "101" }, LP)
1349
+
1350
+ * \#1818 Add capability to choose the key where your `embeds_many` relation
1351
+ is stores. (Cyril Mougel)
1352
+
1353
+ class User
1354
+ include Mongoid::Document
1355
+ field :name, type: String
1356
+ embeds_many :prefs, class_name: "Preference", store_as: 'my_preferences'
1357
+ end
1358
+
1359
+ user.prefs.build(value: "ok")
1360
+ user.save
1361
+ # document saves in MongoDB as:
1362
+ # { "name" => "foo", "my_preferences" => [{ "value" => "ok" }]}
1363
+
1364
+ * \#1806 `Model.find_or_create_by` and `Model.find_or_initialize_by` can now
1365
+ take documents as paramters for belongs_to relations.
1366
+
1367
+ person = Person.first
1368
+ Game.find_or_create_by(person: person)
1369
+
1370
+ * \#1774 Relations now have a :restrict option for dependent relations
1371
+ which will raise an error when attempting to delete a parent that
1372
+ still has children on it. (Hans Hasselberg)
1373
+
1374
+ class Band
1375
+ include Mongoid::Document
1376
+ has_many :albums, dependent: :restrict
1377
+ end
1378
+
1379
+ band = Band.first
1380
+ band.albums << Albums.first
1381
+ band.delete # Raises DeleteRestriction error.
1382
+
1383
+ * \#1764 Add method to check if field differs from the default value.
1384
+
1385
+ class Band
1386
+ include Mongoid::Document
1387
+ field :name, type: String, default: "New"
1388
+ end
1389
+
1390
+ band = Band.first
1391
+ band.name_changed_from_default?
1392
+
1393
+ * \#1759 Invalid fields error messages have been updated to show the
1394
+ source and location of the original method. The new message is:
1395
+
1396
+ Problem:
1397
+ Defining a field named 'crazy_method' is not allowed.
1398
+ Summary:
1399
+ Defining this field would override the method 'crazy_method',
1400
+ which would cause issues with expectations around the original
1401
+ method and cause extremely hard to debug issues.
1402
+ The original method was defined in:
1403
+ Object: MyModule
1404
+ File: /path/to/my/module.rb
1405
+ Line: 8
1406
+ Resolution:
1407
+ Use Mongoid.destructive_fields to see what names are
1408
+ not allowed, and don't use these names. These include names
1409
+ that also conflict with core Ruby methods on Object, Module,
1410
+ Enumerable, or included gems that inject methods into these
1411
+ or Mongoid internals.
1412
+
1413
+ * \#1753/#1649 A setter and getter for has_many relations to set its
1414
+ children is now provided. (Piotr Jakubowski)
1415
+
1416
+ class Album
1417
+ include Mongoid::Document
1418
+ has_many :engineers
1419
+ end
1420
+
1421
+ class Engineer
1422
+ include Mongoid::Document
1423
+ belongs_to :album
1424
+ end
1425
+
1426
+ album = Album.first
1427
+ engineer = Engineer.first
1428
+ album.engineer_ids = [ engineer.id ]
1429
+ album.engineer_ids # Returns the ids of the engineers.
1430
+
1431
+ * \#1741 Mongoid now provides a rake task to force remove indexes for
1432
+ environments where Mongoid manages the index definitions and the
1433
+ removal should be automated. (Hans Hasselberg)
1434
+
1435
+ rake db:force_remove_indexes
1436
+ rake db:mongoid:force_remove_indexes
1437
+
1438
+ * \#1726 `Mongoid.load!` now accepts an optional second argument for the
1439
+ environment to load. This takes precedence over any environment variable
1440
+ that is set if provided.
1441
+
1442
+ Mongoid.load!("/path/to/mongoid.yml", :development)
1443
+
1444
+ * \#1724 Mongoid now supports regex fields.
1445
+
1446
+ class Rule
1447
+ include Mongoid::Document
1448
+ field :pattern, type: Regexp, default: /[^abc]/
1449
+ end
1450
+
1451
+ * \#1714/\#1706 Added better logging on index creation. (Hans Hasselberg)
1452
+
1453
+ When an index is present on a root document model:
1454
+
1455
+ Creating indexes on: Model for: name, dob.
1456
+
1457
+ When an index is defined on an embedded model:
1458
+
1459
+ Index ignored on: Address, please define in the root model.
1460
+
1461
+ When no index is defined, nothing is logged, and if a bad index is
1462
+ defined an error is raised.
1463
+
1464
+ * \#1710 For cases when you don't want Mongoid to auto-protect the id
1465
+ and type attributes, you can set a configuration option to turn this
1466
+ off.
1467
+
1468
+ Mongoid.protect_sensitive_fields = false
1469
+
1470
+ * \#1685 Belongs to relations now have build_ and create_ methods.
1471
+
1472
+ class Comment
1473
+ include Mongoid::Document
1474
+ belongs_to :user
1475
+ end
1476
+
1477
+ comment = Comment.new
1478
+ comment.build_user # Build a new user object
1479
+ comment.create_user # Create a new user object
1480
+
1481
+ * \#1684 Raise a `Mongoid::Errors::InverseNotFound` when attempting to
1482
+ set a child on a relation without the proper inverse_of definitions
1483
+ due to Mongoid not being able to determine it.
1484
+
1485
+ class Lush
1486
+ include Mongoid::Document
1487
+ embeds_one :whiskey, class_name: "Drink"
1488
+ end
1489
+
1490
+ class Drink
1491
+ include Mongoid::Document
1492
+ embedded_in :alcoholic, class_name: "Lush"
1493
+ end
1494
+
1495
+ lush = Lush.new
1496
+ lush.whiskey = Drink.new # raises an InverseNotFound error.
1497
+
1498
+ * \#1680 Polymorphic relations now use `*_type` keys in lookup queries.
1499
+
1500
+ class User
1501
+ include Mongoid::Document
1502
+ has_many :comments, as: :commentable
1503
+ end
1504
+
1505
+ class Comment
1506
+ include Mongoid::Document
1507
+ belongs_to :commentable, polymorphic: true
1508
+ end
1509
+
1510
+ user = User.find(id)
1511
+ user.comments # Uses user.id and type "User" in the query.
1512
+
1513
+ * \#1677 Support for parent separable polymorphic relations to the same
1514
+ parent class is now available. This only works if set from the parent
1515
+ side in order to know which relation the children belong to.
1516
+ (Douwe Maan)
1517
+
1518
+ class Face
1519
+ include Mongoid::Document
1520
+ has_one :left_eye, class_name: "Eye", as: :visible
1521
+ has_one :right_eye, class_name: "Eye", as: :visible
1522
+ end
1523
+
1524
+ class Eye
1525
+ include Mongoid::Document
1526
+ belongs_to :visible, polymorphic: true
1527
+ end
1528
+
1529
+ face = Face.new
1530
+ right_eye = Eye.new
1531
+ left_eye = Eye.new
1532
+ face.right_eye = right_eye
1533
+ face.left_eye = left_eye
1534
+ right_eye.visible = face # Will raise an error.
1535
+
1536
+ * \#1650 Objects that respond to `to_criteria` can now be merged into
1537
+ existing criteria objects.
1538
+
1539
+ class Filter
1540
+ def to_criteria
1541
+ # return a Criteria object.
1542
+ end
1543
+ end
1544
+
1545
+ criteria = Person.where(title: "Sir")
1546
+ criteria.merge(filter)
1547
+
1548
+ * \#1635 All exceptions now provide more comprehensive errors, including
1549
+ the problem that occured, a detail summary of why it happened, and
1550
+ potential resolutions. Example:
1551
+
1552
+ (Mongoid::Errors::DocumentNotFound)
1553
+ Problem:
1554
+ Document not found for class Town with
1555
+ id(s) [BSON::ObjectId('4f35781b8ad54812e1000001')].
1556
+ Summary:
1557
+ When calling Town.find with an id or array of ids,
1558
+ each parameter must match a document in the database
1559
+ or this error will be raised.
1560
+ Resolution:
1561
+ Search for an id that is in the database or set the
1562
+ Mongoid.raise_not_found_error configuration option to
1563
+ false, which will cause a nil to be returned instead
1564
+ of raising this error.
1565
+
1566
+ * \#1616 `Model.find_by` added which takes a hash of arugments to search
1567
+ for in the database. If no single document is returned a DocumentNotFound
1568
+ error is raised. (Piotr Jakubowski)
1569
+
1570
+ Band.find_by(name: "Depeche Mode")
1571
+
1572
+ * \#1606 Mongoid now enables autosave, like Active Record, when adding
1573
+ an accepts_nested_attributes_for to a relation.
1574
+
1575
+ class Band
1576
+ include Mongoid::Document
1577
+ has_many :albums
1578
+ accepts_nested_attributes_for :albums # This enables the autosave.
1579
+ end
1580
+
1581
+ * \#1477 Mongoid now automatically protects the id and type attributes
1582
+ from mass assignment. You can override this (not recommended) by redefining
1583
+ them as accessible.
1584
+
1585
+ class Band
1586
+ include Mongoid::Document
1587
+ attr_accessible :id, :_id, :_type
1588
+ end
1589
+
1590
+ * \#1459 The identity map can be disabled now for specific code execution
1591
+ by passing options to the unit of work.
1592
+
1593
+ Mongoid.unit_of_work(disable: :all) do
1594
+ # Disables the identity map on all threads for the block.
1595
+ end
1596
+
1597
+ Mongoid.unit_of_work(disable: :current) do
1598
+ # Disables the identity map on the current thread for the block.
1599
+ end
1600
+
1601
+ Mongoid.unit_of_work do
1602
+ # Business as usual.
1603
+ end
1604
+
1605
+ * \#1355 Associations now can have safety options provided to them on single
1606
+ document persistence operations.
1607
+
1608
+ band.albums.with(safe: true).push(album)
1609
+ band.albums.with(safe: true).create(name: "Smiths")
1610
+
1611
+ album.with(safe: true).create_producer(name: "Flood")
1612
+
1613
+ * \#1348 Eager loading is now supported on many-to-many relations.
1614
+
1615
+ * \#1292 Remove attribute now unsets the attribute when the document is
1616
+ saved instead of setting to nil.
1617
+
1618
+ band = Band.find(id)
1619
+ band.remove_attribute(:label) # Uses $unset when the document is saved.
1620
+
1621
+ * \#1291 Mongoid database sessions are now connected to lazily, and are
1622
+ completely thread safe. If a new thread is created, then a new database
1623
+ session will be created for it.
1624
+
1625
+ * \#1291 Mongoid now supports any number of database connections as defined in
1626
+ the mongoid.yml. For example you could have a local single server db, a
1627
+ multi availablity zone replica set, and a shard cluster all in the same
1628
+ application environment. Mongoid can connect to any session at any point in
1629
+ time.
1630
+
1631
+ * \#1291 Mongoid now allows you to persist to whatever database or collection
1632
+ you like at runtime, on a per-query or persistence operation basis by using
1633
+ `with`.
1634
+
1635
+ Band.with(collection: "artists").create(name: "Depeche Mode")
1636
+ band.with(database: "secondary).save!
1637
+ Band.with(collection: "artists").where(name: "Depeche Mode")
1638
+
1639
+ * \#1291 You can now configure on a per-model basis where its documents are
1640
+ stored with the new and improved `store_in` macro.
1641
+
1642
+ class Band
1643
+ include Mongoid::Document
1644
+ store_in collection: "artists", database: "secondary", session: "replica"
1645
+ end
1646
+
1647
+ This can be overridden, of course, at runtime via the `with` method.
1648
+
1649
+ * \#1212 Embedded documents can now be popped off a relation with persistence.
1650
+
1651
+ band.albums.pop # Pop 1 document and persist the removal.
1652
+ band.albums.pop(3) # Pop 3 documents and persist the removal.
1653
+
1654
+ * \#1188 Relations now have existence predicates for simplified checking if the
1655
+ relation is blank or not. (Andy Morris)
1656
+
1657
+ class Band
1658
+ include Mongoid::Document
1659
+ embeds_many :albums
1660
+ embeds_one :label
1661
+ end
1662
+
1663
+ band = Band.new
1664
+ band.albums?
1665
+ band.has_albums?
1666
+ band.label?
1667
+ band.has_label?
1668
+
1669
+ * \#1188 1-1 relations now have an :autobuild option to indicate if the
1670
+ relation should automatically be build with empty attributes upon access
1671
+ where the relation currently does not exist. Works on embeds_one,
1672
+ embedded_in, has_one, belongs_to. (Andy Morris)
1673
+
1674
+ class Band
1675
+ include Mongoid::Document
1676
+ has_one :label, autobuild: true
1677
+ end
1678
+
1679
+ band = Band.new
1680
+ band.label # Returns a new label with empty attributes.
1681
+
1682
+ When using existence checks, autobuilding will not execute.
1683
+
1684
+ band = Band.new
1685
+ band.label? # Returns false, does not autobuild on a check.
1686
+ band.has_label? # Returns false, does not autobuild on a check.
1687
+
1688
+ * \#1081 Mongoid indexes both id and type as a compound index when providing
1689
+ `index: true` to a polymorphic belongs_to.
1690
+
1691
+ class Comment
1692
+ include Mongoid::Document
1693
+
1694
+ # Indexes commentable_id and commentable_type as a compound index.
1695
+ belongs_to :commentable, polymorphic: true, index: true
1696
+ end
1697
+
1698
+ * \#1053 Raise a `Mongoid::Errors::UnknownAttribute` instead of no method
1699
+ when attempting to set a field that is not defined and allow dynamic
1700
+ fields is false. (Cyril Mougel)
1701
+
1702
+ Mongoid.allow_dynamic_fields = false
1703
+
1704
+ class Person
1705
+ include Mongoid::Document
1706
+ field :title, type: String
1707
+ end
1708
+
1709
+ Person.new.age = 50 # raises the UnknownAttribute error.
1710
+
1711
+ * \#772 Fields can now be flagged as readonly, which will only let their
1712
+ values be set when the document is new.
1713
+
1714
+ class Band
1715
+ include Mongoid::Document
1716
+ field :name, type: String
1717
+ field :genre, type: String
1718
+
1719
+ attr_readonly :name, :genre
1720
+ end
1721
+
1722
+ Readonly values are ignored when attempting to set them on persisted
1723
+ documents, with the exception of update_attribute and remove_attribute,
1724
+ where errors will get raised.
1725
+
1726
+ band = Band.create(name: "Depeche Mode")
1727
+ band.update_attribute(:name, "Smiths") # Raises ReadonlyAttribute error.
1728
+ band.remove_attribute(:name) # Raises ReadonlyAttribute error.
1729
+
1730
+
1731
+ ### Major Changes (Backwards Incompatible)
1732
+
1733
+ * Polymorphic relations can not have ids other than object ids. This is
1734
+ because Mongoid cannot properly figure out in an optimized way what the
1735
+ various classes on the other side of the relation store their ids as, as
1736
+ they could potentially all be different.
1737
+
1738
+ This was not allowed before, but nowhere was it explicitly stated.
1739
+
1740
+ * \#2039 Validating presence of a relation now checks both the relation and
1741
+ the foreign key value.
1742
+
1743
+ * Indexing syntax has changed. The first parameter is now a hash of
1744
+ name/direction pairs with an optional second hash parameter for
1745
+ additional options.
1746
+
1747
+ Normal indexing with options, directions are either 1 or -1:
1748
+
1749
+ class Band
1750
+ include Mongoid::Document
1751
+ field :name, type: String
1752
+
1753
+ index({ name: 1 }, { unique: true, background: true })
1754
+ end
1755
+
1756
+ Geospacial indexing needs "2d" as its direction.
1757
+
1758
+ class Venue
1759
+ include Mongoid::Document
1760
+ field :location, type: Array
1761
+
1762
+ index location: "2d"
1763
+ end
1764
+
1765
+ * Custom serializable fields have revamped. Your object no longer should
1766
+ include `Mongoid::Fields::Serializable` - instead it only needs to
1767
+ implement 3 methods: `#mongoize`, `.demongoize` and `.evolve`.
1768
+
1769
+ `#mongoize` is an instance method that transforms your object into
1770
+ a mongo-friendly value.
1771
+
1772
+ `.demongoize` is a class method, that can take some data from mongo
1773
+ and instantiate and object of your custom type.
1774
+
1775
+ `.evolve` is a class method, that can take any object, and
1776
+ transform it for use in a `Mongoid::Criteria`.
1777
+
1778
+ An example of an implementation of this for `Range`:
1779
+
1780
+ class Range
1781
+
1782
+ def mongoize
1783
+ { "min" => first, "max" => last }
1784
+ end
1785
+
1786
+ class << self
1787
+
1788
+ def demongoize(object)
1789
+ Range.new(object["min"], object["max"])
1790
+ end
1791
+
1792
+ def evolve(object)
1793
+ { "$gte" => object.first, "$lte" => object.last }
1794
+ end
1795
+ end
1796
+ end
1797
+
1798
+ * `Document#changes` is no longer a hash with indifferent access.
1799
+
1800
+ * `after_initialize` callbacks no longer cascade to children if the option
1801
+ is set.
1802
+
1803
+ * \#1865 `count` on the memory and mongo contexts now behave exactly the
1804
+ same as Ruby's `count` on enumerable, and can take an object or a block.
1805
+ This is optimized on the mongo context not to load everything in memory
1806
+ with the exception of passing a block.
1807
+
1808
+ Band.where(name: "Tool").count
1809
+ Band.where(name: "Tool").count(tool) # redundant.
1810
+ Band.where(name: "Tool") do |doc|
1811
+ doc.likes > 0
1812
+ end
1813
+
1814
+ Note that although the signatures are the same for both the memory and
1815
+ mongo contexts, it's recommended you only use the block syntax for the
1816
+ memory context since the embedded documents are already loaded into
1817
+ memory.
1818
+
1819
+ Also note that passing a boolean to take skip and limit into account
1820
+ is no longer supported, as this is not necessarily a useful feature.
1821
+
1822
+ * The `autocreate_indexes` configuration option has been removed.
1823
+
1824
+ * `Model.defaults` no longer exists. You may get all defaults with a
1825
+ combination of `Model.pre_processed_defaults` and
1826
+ `Model.post_processed_defaults`.
1827
+
1828
+ Band.pre_processed_defaults
1829
+ Band.post_processed_defaults
1830
+
1831
+ * `Model.identity` and `Model.key` have been removed. For custom ids,
1832
+ users must now override the _id field.
1833
+
1834
+ When the default value is a proc, the default is applied *after* all
1835
+ other attributes are set.
1836
+
1837
+ class Band
1838
+ include Mongoid::Document
1839
+ field :_id, type: String, default: ->{ name }
1840
+ end
1841
+
1842
+ To have the default applied *before* other attributes, set `:pre_processed`
1843
+ to true.
1844
+
1845
+ class Band
1846
+ include Mongoid::Document
1847
+ field :_id,
1848
+ type: String,
1849
+ pre_processed: true,
1850
+ default: ->{ BSON::ObjectId.new.to_s }
1851
+ end
1852
+
1853
+ * Custom application exceptions in various languages has been removed,
1854
+ along with the `Mongoid.add_language` feature.
1855
+
1856
+ * Mongoid no longer supports 1.8. MRI 1.9.3 and higher, or JRuby 1.6 and
1857
+ higher in 1.9 mode are only supported.
1858
+
1859
+ * \#1734 When searching for documents via `Model.find` with multiple ids,
1860
+ Mongoid will raise an error if not *all* ids are found, and tell you
1861
+ what the missing ones were. Previously the error only got raised if
1862
+ nothing was returned.
1863
+
1864
+ * \#1675 Adding presence validation on a relation now enables autosave.
1865
+ This is to ensure that when a new parent object is saved with a new
1866
+ child and marked is valid, both are persisted to ensure a correct
1867
+ state in the database.
1868
+
1869
+ * \#1491 Ensure empty translations returns an empty hash on access.
1870
+
1871
+ * \#1484 `Model#has_attribute?` now behaves the same as Active Record.
1872
+
1873
+ * \#1471 Mongoid no longer strips any level of precision off of times.
1874
+
1875
+ * \#1475 Active support's time zone is now used by default in time
1876
+ serialization if it is defined.
1877
+
1878
+ * \#1342 `Model.find` and `model.relation.find` now only take a single or
1879
+ multiple ids. The first/last/all with a conditions hash has been removed.
1880
+
1881
+ * \#1291 The mongoid.yml has been revamped completely, and upgrading
1882
+ existing applications will greet you with some lovely Mongoid specific
1883
+ configuration errors. You can re-generate a new mongoid.yml via the
1884
+ existing rake task, which is commented to an insane degree to help you
1885
+ with all the configuration possibilities.
1886
+
1887
+ * \#1291 The `persist_in_safe_mode` configuration option has been removed.
1888
+ You must now tell a database session in the mongoid.yml whether or not
1889
+ it should persist in safe mode by default.
1890
+
1891
+ production:
1892
+ sessions:
1893
+ default:
1894
+ database: my_app_prod
1895
+ hosts:
1896
+ - db.app.com:27018
1897
+ - db.app.com:27019
1898
+ options:
1899
+ consistency: :eventual
1900
+ safe: true
1901
+
1902
+ * \#1291 `safely` and `unsafely` have been removed. Please now use `with`
1903
+ to provide safe mode options at runtime.
1904
+
1905
+ Band.with(safe: true).create
1906
+ band.with(safe: { w: 3 }).save!
1907
+ Band.with(safe: false).create!
1908
+
1909
+ * \#1270 Relation macros have been changed to match their AR counterparts:
1910
+ only :has_one, :has_many, :has_and_belongs_to_many, and :belongs_to
1911
+ exist now.
1912
+
1913
+ * \#1268 `Model#new?` has been removed, developers must now always use
1914
+ `Model#new_record?`.
1915
+
1916
+ * \#1182 A reload is no longer required to refresh a relation after setting
1917
+ the value of the foreign key field for it. Note this behaves exactly as
1918
+ Active Record.
1919
+
1920
+ If the id is set, but the document for it has not been persisted, accessing
1921
+ the relation will return empty results.
1922
+
1923
+ If the id is set and its document is persisted, accessing the relation
1924
+ will return the document.
1925
+
1926
+ If the id is set, but the base document is not saved afterwards, then
1927
+ reloading will return the document to its original state.
1928
+
1929
+ * \#1093 Field serialization strategies have changed on Array, Hash, Integer
1930
+ and Boolean to be more consistent and match AR where appropriate.
1931
+
1932
+ Serialization of arrays calls `Array.wrap(object)`
1933
+ Serialization of hashes calls `Hash[object]` (to_hash on the object)
1934
+ Serialization of integers always returns an int via `to_i`
1935
+ Serialization of booleans defaults to false instead of nil.
1936
+
1937
+ * \#933 `:field.size` has been renamed to `:field.count` in criteria for
1938
+ $size not to conflict with Symbol's size method.
1939
+
1940
+ * \#829/\#797 Mongoid scoping code has been completely rewritten, and now
1941
+ matches the Active Record API. With this backwards incompatible change,
1942
+ some methods have been removed or renamed.
1943
+
1944
+ Criteria#as_conditions and Criteria#fuse no longer exist.
1945
+
1946
+ Criteria#merge now only accepts another object that responds to
1947
+ `to_criteria`.
1948
+
1949
+ Criteria#merge! now merges in another object without creating a new
1950
+ criteria object.
1951
+
1952
+ Band.where(name: "Tool").merge!(criteria)
1953
+
1954
+ Named scopes and default scopes no longer take hashes as parameters.
1955
+ From now on only criteria and procs wrapping criteria will be
1956
+ accepted, and an error will be raised if the arguments are incorrect.
1957
+
1958
+ class Band
1959
+ include Mongoid::Document
1960
+
1961
+ default_scope ->{ where(active: true) }
1962
+ scope :inactive, where(active: false)
1963
+ scope :invalid, where: { valid: false } # This will raise an error.
1964
+ end
1965
+
1966
+ The 'named_scope' macro has been removed, from now on only use 'scope'.
1967
+
1968
+ Model.unscoped now accepts a block which will not allow default scoping
1969
+ to be applied for any calls inside the block.
1970
+
1971
+ Band.unscoped do
1972
+ Band.scoped.where(name: "Ministry")
1973
+ end
1974
+
1975
+ Model.scoped now takes options that will be set directly on the criteria
1976
+ options hash.
1977
+
1978
+ Band.scoped(skip: 10, limit: 20)
1979
+
1980
+ * \#463 `Document#upsert` is no longer aliased to `Document#save` and now
1981
+ actually performs a proper MongoDB upsert command when called. If you
1982
+ were using this method before and want the same behaviour, please switch
1983
+ to `save`.
1984
+
1985
+ band = Band.new(name: "Tool")
1986
+ band.upsert #=> Inserts the document in the database.
1987
+ band.name = "Placebo"
1988
+ band.upsert #=> Updates the existing document.
1989
+
1990
+ ### Resolved Issues
1991
+
1992
+ * \#2166 `Criteria#from_map_or_db` strips type selection when eager loading
1993
+ since it will check if the type is correct after.
1994
+
1995
+ * \#2129 Fixed sorting for all fields on embeds many relations.
1996
+
1997
+ * \#2124 Fixed default scope and deleted scope on paranoid documents.
1998
+
1999
+ * \#2122 Allow embedded documents to sort on boolean fields.
2000
+
2001
+ * \#2119 Allow `Criteria#update_all` to accept atomic ops and normal sets.
2002
+
2003
+ * \#2118 Don't strip any precision during `DateTime` -> `Time` conversions.
2004
+
2005
+ * \#2117 Ensure embeds one relations have callbacks run when using nested
2006
+ attributes.
2007
+
2008
+ * \#2110 `Model#touch` now works properly on embedded documents.
2009
+
2010
+ * \#2100 Allow atomic operations to properly execute on paranoid documents
2011
+ that have a deleted_at set.
2012
+
2013
+ * \#2089 Allow proper separation of mongoization and evolving with respect to
2014
+ foreign keys.
2015
+
2016
+ * \#2088 Allow finds by string ids to pull from the identity map if the ids
2017
+ are stored as object ids.
2018
+
2019
+ * \#2085 Allow demongoization of floats and ints to big decimals.
2020
+
2021
+ * \#2084 Don't cascade if metadata does not exist.
2022
+
2023
+ * \#2078 Calling `Model#clone` or `Model#dup` now properly sets attributes
2024
+ as dirty.
2025
+
2026
+ * \#2070 Allow for updated_at to be overridden manually for new documents that
2027
+ also have a created_at.
2028
+
2029
+ * \#2041 Don't hit the database multiple times on relation access after an
2030
+ eager load returned zero documents.
2031
+
2032
+ * \#1997 Cascading callbacks should be able to halt the callback chain when
2033
+ terminating.
2034
+
2035
+ * \#1972 `added`, `loaded`, and `unloaded` can now be valid scope names on a
2036
+ document that is part of a 1-n relation.
2037
+
2038
+ * \#1952/#1950 `#all_in` behaviour on embedded documents now properly matches
2039
+ root documents when passing an empty array. (Hans Hasselberg)
2040
+
2041
+ * \#1941/#1939 `Model.find_by` now returns nil if raise not found error is
2042
+ set to false. (Hans Hasselberg)
2043
+
2044
+ * \#1859/#1860 `Model#remove_attribute` now properly unsets on embedded
2045
+ documents. (Anton Onyshchenko)
2046
+
2047
+ * \#1852 Ensure no infinite recursion on cascading callbacks. (Ara Howard)
2048
+
2049
+ * \#1823 `Relation#includes?` now properly works with identity map enabled.
2050
+
2051
+ * \#1810 `Model#changed?` no longer returns true when hash and array fields
2052
+ have only been accessed.
2053
+
2054
+ * \#1876/\#1782 Allow dot notation in embeds many criteria queries.
2055
+ (Cyril Mougel)
2056
+
2057
+ * \#1745 Fixed batch clear to work within attribute setting.
2058
+
2059
+ * \#1718 Ensure consistency of #first/#last in relations - they now always
2060
+ match first/last in the database, but opts for in memory first.
2061
+
2062
+ * \#1692/\#1376 `Model#updateattributes` and `Model#update_attributes!` now
2063
+ accept assignment options. (Hans Hasselberg)
2064
+
2065
+ * \#1688/\#1207 Don't require namespacing when providing class name on
2066
+ relation macros inside the namespace. (Hans Hasselberg)
2067
+
2068
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
2069
+ \#matches. (Hans Hasselberg)
2070
+
2071
+ * \#1335 Don't add id sorting criteria to first/last is there is already
2072
+ sorting options on the criteria.
2073
+
2074
+ * \#1321 Referenced many enumerable targets are now hash-backed, preventing
2075
+ duplicates in a more efficient manner.
2076
+
2077
+ * \#1135 DateTimes now properly get time zones on deserialization.
2078
+
2079
+ * \#1031 Mongoid now serializes values in Array fields to their proper
2080
+ Mongo-friendly values when possible.
2081
+
2082
+ * \#685 Attempting to use versioning with embedded documents will now
2083
+ raise a proper error alerting the developer this is not allowed.
2084
+
2085
+ ## 2.6.0
2086
+
2087
+ ### New Features
2088
+
2089
+ * \#2709 Backported the `touch` functionality from Mongoid 3.
2090
+
2091
+ ## 2.5.2
2092
+
2093
+ ### Resolved Issues
2094
+
2095
+ * \#2502 Fixed cache key to properly handle when the document does not
2096
+ include `Mongoid::Timestamps::Updated`. (Arthur Nogueira Neves)
2097
+
2098
+ ## 2.5.1
2099
+
2100
+ ### Resolved Issues
2101
+
2102
+ * \#2492 Backport cascading callbacks performance and memory fixes from
2103
+ 3.0.0-stable.
2104
+
2105
+ * \#2464 Backport the nested attributes fix for keeping many relations in
2106
+ memory when updating attributes. (Chris Thompson)
2107
+
2108
+ ## 2.5.0
2109
+
2110
+ ### New Features
2111
+
2112
+ * This is a release to support the 1.7.0 and higher Mongo and BSON gems and
2113
+ resolves issues that kept the 2.4.x series locked below 1.6.2
2114
+
2115
+ ## 2.4.12
2116
+
2117
+ ### Resolved Issues
2118
+
2119
+ * \#2178 Ensure destroy callbacks are run post replacement of an embeds one
2120
+ relation.
2121
+
2122
+ * \#2169 Allow saves to pass when documents are destroyed after the save
2123
+ in a callback.
2124
+
2125
+ * \#2144 Uniqueness validation on paranoid documents now properly scopes.
2126
+
2127
+ * \#2127 Don't unbind parents of embedded documents mid nested
2128
+ attributes deletion.
2129
+
2130
+ ## 2.4.11
2131
+
2132
+ ### Resolved Issues
2133
+
2134
+ * This release forces a cap on the mongo driver version at 1.6.2 due to
2135
+ changes in the `Mongo::Connection.from_uri` API not allowing valid
2136
+ connection options anymore.
2137
+
2138
+ * \#2040 Fixed bad interpolation for locale presence validation.
2139
+
2140
+ * \#2038 Allow inverse relations to be determined by foreign keys alone
2141
+ if defined on both sides, not just an inverse_of declaration.
2142
+
2143
+ * \#2023 Allow serilialization of dynamic types that conflict with core
2144
+ Ruby methods to still be serialized.
2145
+
2146
+ * \#2008 Presence validation should hit the db to check validity if the
2147
+ relation in memory is blank.
2148
+
2149
+ * \#2006 Allow excluding only the _id field post execution of an #only call.
2150
+
2151
+ ## 2.4.10
2152
+
2153
+ ### Resolved Issues
2154
+
2155
+ * \#2003 Don't fail on document generation when an embedded document was
2156
+ stored as nil in the database.
2157
+
2158
+ * \#1997 Don't delete paranoid embedded docs via nested attributes when
2159
+ a before_destroy callback returns false.
2160
+
2161
+ * \#1994 `dependent: :delete` only hits the database once now for one to
2162
+ many and many to many relations instead of once for each document.
2163
+
2164
+ * \#1987 Don't double-insert documents into identity map when eager loading
2165
+ twice inside the unit of work.
2166
+
2167
+ * \#1953 Uniqueness validation now works on localized fields.
2168
+
2169
+ * \#1936 Allow setting n levels deep embedded documents atomically without
2170
+ conflicting mods when not using nested attributes or documents themselves
2171
+ in an update call from the parent.
2172
+
2173
+ * \#1957/\#1954 Ensure database name is set with inheritance.
2174
+ (Hans Hasselberg)
2175
+
2176
+ ## 2.4.9
2177
+
2178
+ ### Resolved Issues
2179
+
2180
+ * \#1943 Ensure numericality validation works for big decimals.
2181
+
2182
+ * \#1938 Length validation now works with localized fields.
2183
+
2184
+ * \#1936 Conflicting pushes with other pushes is now properly handled.
2185
+
2186
+ * \#1933 `Proxy#extend` should delegate through to the target, where
2187
+ extending the proxy itself is now handled through `Proxy#proxy_extend`.
2188
+
2189
+ * \#1930 Ensure complex criteria are expanded in all where clauses.
2190
+ (Hans Hasselberg)
2191
+
2192
+ * \#1928 Deletion of embedded documents via nested attributes now performs
2193
+ a $pull with id match criteria instead of a $pullAll to cover all cases.
2194
+ Previously newly added defaults to documents that had already persisted
2195
+ could not be deleted in this matter since the doc did not match what was
2196
+ in the database.
2197
+
2198
+ * \#1924/\#1917 Fix pushing to embedded relations with default scopes not
2199
+ scoping on the new document. (Hans Hasselberg)
2200
+
2201
+ * \#1922/\#1919 Dropping collections unmemoizes the internally wrapped
2202
+ collection, in order to ensure when defining capped collections that
2203
+ they are always recreated as capped. (Hans Hasselberg)
2204
+
2205
+ * \#1916/\#1913 Uniqueness validation no longer is affected by the default
2206
+ scope. (Hans Hasselberg)
2207
+
2208
+ * \#1943 Ensure numericality validation works for big decimals.
2209
+
2210
+ ## 2.4.8
2211
+
2212
+ ### Resolved Issues
2213
+
2214
+ * \#1892 When getting not master operation error, Mongoid should reconnect
2215
+ before retrying the operation.
2216
+
2217
+ * \#1887 Don't cascade callbacks to children that don't have the callback
2218
+ defined.
2219
+
2220
+ * \#1882 Don't expand duplicate id criterion into an $and with duplicate
2221
+ selections.
2222
+
2223
+ * \#1878 Fixed default application values not to apply in certain `only`
2224
+ or `without` selection on iteration, not just `first` and `last`.
2225
+
2226
+ * \#1874 Fixed the reject all blank proc constant to handle values
2227
+ properly with a destroy non blank value. (Stefan Daschek)
2228
+
2229
+ * \#1869/\#1868 Delayed atomic sets now uses the atomic path instead of
2230
+ the metadata name to fix multiple level embedding issues.
2231
+ (Chris Micacchi provided specs)
2232
+
2233
+ * \#1866 Post processed defaults (procs) should be applied post binding
2234
+ of the child in a relation.build.
2235
+
2236
+ ## 2.4.7
2237
+
2238
+ ### Resolved Issues
2239
+
2240
+ * Ensure reloading of embedded documents retains reference to the parent.
2241
+
2242
+ * \#1837 Always pass symbol options to the driver.
2243
+
2244
+ * \#1836 Ensure relation counts pick up persisted document that have not
2245
+ had the foreign key link persisted.
2246
+
2247
+ * \#1820 Destroying embedded documents in an embeds_many should also
2248
+ removed the document from the underlying _uncoped target and reindex
2249
+ the relation.
2250
+
2251
+ * \#1814 Don't cascade callbacks on after_initialize.
2252
+
2253
+ * \#1800 Invalid options for the Mongo connection are now filtered out.
2254
+
2255
+ * \#1785 Case equality has been fixed to handle instance checks properly.
2256
+
2257
+ ## 2.4.6
2258
+
2259
+ ### Resolved Issues
2260
+
2261
+ * \#1772 Allow skip and limit to convert strings to integers. (Jean Boussier)
2262
+
2263
+ * \#1767 Model#update_attributes accepts mass assignment options again.
2264
+ (Hans Hasselberg)
2265
+
2266
+ * \#1762 Criteria#any_of now properly handles localized fields.
2267
+
2268
+ * \#1758 Metadata now returns self on options for external library support.
2269
+
2270
+ * \#1757 Ensure serialization converts any attribute types to the type
2271
+ defined by the field.
2272
+
2273
+ * \#1756 Serializable hash options should pass through to embedded docs.
2274
+
2275
+ ## 2.4.5
2276
+
2277
+ ### Resolved Issues
2278
+
2279
+ * \#1751 Mongoid's logger now responds to level for Ruby logging API
2280
+ compatibility.
2281
+
2282
+ * \#1744/#1750 Sorting works now for localized fields in embedded documents
2283
+ using the criteria API. (Hans Hasselberg)
2284
+
2285
+ * \#1746 Presence validation now shows which locales were empty for
2286
+ localized fields. (Cyril Mougel)
2287
+
2288
+ * \#1727 Allow dot notation in embedded criteria to work on both embeds one
2289
+ and embeds many. (Lyle Underwood)
2290
+
2291
+ * \#1723 Initialize callbacks should cascade through children without needing
2292
+ to determine if the child is changed.
2293
+
2294
+ * \#1715 Serializable hashes are now consistent on inclusion of embedded
2295
+ documents per or post save.
2296
+
2297
+ * \#1713 Fixing === checks when comparing a class with an instance of a
2298
+ subclass.
2299
+
2300
+ * \#1495 Callbacks no longer get the 'super called outside of method` errors on
2301
+ busted 1.8.7 rubies.
2302
+
2303
+ ## 2.4.4
2304
+
2305
+ ### Resolved Issues
2306
+
2307
+ * \#1705 Allow changing the order of many to many foreign keys.
2308
+
2309
+ * \#1703 Updated at is now versioned again. (Lucas Souza)
2310
+
2311
+ * \#1686 Set the base metadata on unbind as well as bind for belongs to
2312
+ relations.
2313
+
2314
+ * \#1681 Attempt to create indexes for models without namespacing if the
2315
+ namespace does not exist for the subdirectory.
2316
+
2317
+ * \#1676 Allow eager loading to work as a default scope.
2318
+
2319
+ * \#1665/\#1672 Expand complex criteria in nested criteria selectors, like
2320
+ \#matches. (Hans Hasselberg)
2321
+
2322
+ * \#1668 Ensure Mongoid logger exists before calling warn. (Rémy Coutable)
2323
+
2324
+ * \#1661 Ensure uniqueness validation works on cloned documents.
2325
+
2326
+ * \#1659 Clear delayed atomic sets when resetting the same embedded relation.
2327
+
2328
+ * \#1656/\#1657 Don't hit database for uniqueness validation if BOTH scope
2329
+ and attribute hasn't changed. (priyaaank)
2330
+
2331
+ * \#1205/\#1642 When limiting fields returned from the database via
2332
+ `Criteria#only` and `Criteria#without` and then subsequently saving
2333
+ the document. Default values no longer override excluded fields.
2334
+
2335
+ ## 2.4.3
2336
+
2337
+ ### Resolved Issues
2338
+
2339
+ * \#1647 DateTime serialization when already in UTC does not convert to
2340
+ local time.
2341
+
2342
+ * \#1641/\#1639 Mongoid.observer.disable :all now behaves as AR does.
2343
+
2344
+ * \#1640 Update consumers should be tied to the name of the collection
2345
+ they persist to, not the name of the class.
2346
+
2347
+ * \#1637/\#1636 Scopes no longer modify parent class scopes when subclassing.
2348
+ (Hans Hasselberg)
2349
+
2350
+ * \#1629 $all and $in criteria on embedded many relations now properly
2351
+ handles regex searches and elements of varying length. (Douwe Maan)
2352
+
2353
+ * \#1623/\#1634 Default scopes no longer break Mongoid::Versioning.
2354
+ (Hans Hasselberg)
2355
+
2356
+ * \#1605 Fix regression of rescue responses, Rails 3.2
2357
+
2358
+ ## 2.4.2
2359
+
2360
+ ### Resolved Issues
2361
+
2362
+ * \#1628 _type field can once again be included in serialization to json
2363
+ or xml as a global option with `include_type_for_serialization`.
2364
+ (Roman Shterenzon)
2365
+
2366
+ * \#1627 Validating format now works properly with localized fields.
2367
+ (Douwe Maan)
2368
+
2369
+ * \#1617 Relation proxy methods now show up in Mongoid's list of
2370
+ prohibited fields.
2371
+
2372
+ * \#1615 Allow a single configuration of host and port for all spec runs,
2373
+ overridden by setting MONGOID_SPEC_HOST and MONGOID_SPEC_PORT env vars.
2374
+
2375
+ * \#1610 When versioning paranoid documents and max version is set, hard
2376
+ delete old versions from the embedded relation.
2377
+
2378
+ * \#1609 Allow connection retry during cursor iteration as well as all other
2379
+ operations.
2380
+
2381
+ * \#1608 Guard against no method errors when passing ids in nested attributes
2382
+ and the documents do not exist.
2383
+
2384
+ * \#1605 Remove deprecation warning on rescue responses, Rails 3.2
2385
+
2386
+ * \#1602 Preserve structure of $and and $or queries when typecasting.
2387
+
2388
+ * \#1600 Uniqueness validation no longer errors when provided a relation.
2389
+
2390
+ * \#1599 Make sure enumerable targets yield to what is in memory first when
2391
+ performing #each, not always the unloaded first.
2392
+
2393
+ * \#1597 Fix the ability to change the order of array fields with the same
2394
+ elements.
2395
+
2396
+ * \#1590 Allow proper serialization of boolean values in criteria where the
2397
+ field is nested inside an array.
2398
+
2399
+ ## 2.4.1
2400
+
2401
+ ### Resolved Issues
2402
+
2403
+ * \#1593 Arrays on embedded documents now properly atomically update when
2404
+ modified from original version.
2405
+
2406
+ * \#1592 Don't swallow exceptions from index generation in the create_indexes
2407
+ rake task.
2408
+
2409
+ * \#1589 Allow assignment of empty array to HABTM when no documents are yet
2410
+ loaded into memory.
2411
+
2412
+ * \#1587 When a previous value for an array field was an explicit nil, it can
2413
+ now be reset atomically with new values.
2414
+
2415
+ * \#1585 `Model#respond_to?` returns true now for the setter when allowing
2416
+ dynamic fields.
2417
+
2418
+ * \#1582 Allow nil values to be set in arrays.
2419
+
2420
+ * \#1580 Allow arrays to be set to nil post save, and not just empty.
2421
+
2422
+ * \#1579 Don't call #to_a on individual set field elements in criterion.
2423
+
2424
+ * \#1576 Don't hit database on uniqueness validation if the field getting
2425
+ validated has not changed.
2426
+
2427
+ * \#1571 Aliased fields get all the dirty attribute methods and all getters and
2428
+ setters for both the original name and the alias. (Hans Hasselberg)
2429
+
2430
+ * \#1568 Fallback to development environment with warning when no env configured.
2431
+
2432
+ * \#1565 For fields and foreign keys with non-standard Ruby or database names,
2433
+ use define_method instead of class_eval for creating the accessors and
2434
+ dirty methods.
2435
+
2436
+ * \#1557 Internal strategy class no longer conflicts with models.
2437
+
2438
+ * \#1551 Parent documents now return `true` for `Model#changed?` if only child
2439
+ (embedded) documents have changed.
2440
+
2441
+ * \#1547 Resetting persisted children from a parent save when new waits until post
2442
+ callbacks, mirroring update functionality.
2443
+
2444
+ * \#1536 Eager loading now happens when calling `first` or `last` on a
2445
+ criteria if inclusions are specified.
2446
+
2447
+ ## 2.4.0
2448
+
2449
+ ### New Features
2450
+
2451
+ * Ranges can now be passed to #where criteria to create a $gte/$lte query under the
2452
+ covers. `Person.where(dob: start_date...end_date)`
2453
+
2454
+ * Custom serializable fields can now override #selection to provide
2455
+ customized serialization for criteria queries.
2456
+
2457
+ * \#1544 Internals use `Array.wrap` instead of `to_a` now where possible.
2458
+
2459
+ * \#1511 Presence validation now supports localized fields. (Tiago Rafael Godinho)
2460
+
2461
+ * \#1506 `Model.set` will now accept false and nil values. (Marten Veldthuis)
2462
+
2463
+ * \#1505 `Model.delete_all/destroy_all` now take either a :conditions hash or
2464
+ the attributes directly.
2465
+
2466
+ * \#1504 `Model.recursively_embeds_many` now accepts a :cascade_callbacks
2467
+ option. (Pavel Pravosud)
2468
+
2469
+ * \#1496 Mongoid now casts strings back to symbols for symbol fields that
2470
+ get saved as strings by another application.
2471
+
2472
+ * \#1454, \#900 Associations now have an `after_build` callback that gets
2473
+ executed after `.build` or `build_` methods are called.
2474
+ (Jeffrey Jones, Ryan Townsend)
2475
+
2476
+ * \#1451 Ranges can now be any range value, not just numbers. (aupajo)
2477
+
2478
+ * \#1448 Localization is now used when sorting. (Hans Hasselberg)
2479
+
2480
+ * \#1422 Mongoid raises an error at yaml load if no environment is found.
2481
+ (Tom Stuart)
2482
+
2483
+ * \#1413 $not support added to criteria symbol methods. (Marc Weil)
2484
+
2485
+ * \#1403 Added configuration option `scope_overwrite_exception` which defaults to
2486
+ false for raising an error when defining a named scope with the same name of
2487
+ an existing method. (Christoph Grabo)
2488
+
2489
+ * \#1388 `model.add_to_set` now supports adding multiple values and performs an
2490
+ $addToSet with $each under the covers. (Christian Felder)
2491
+
2492
+ * \#1387 Added `Model#cache_key` for use in Rails caching. (Seivan Heidari)
2493
+
2494
+ * \#1380 Calling Model.find(id) will now properly convert to and from any type
2495
+ based on the type of the _id field.
2496
+
2497
+ * \#1363 Added fallbacks and default support to localized fields, and added
2498
+ ability to get and set all translations at once.
2499
+
2500
+ * \#1362 Aliased fields now properly typecast in criteria.
2501
+
2502
+ * \#1337 Array fields, including HABTM many foreign keys now have smarter dirty
2503
+ checking and no longer perform a simple $set if the array has changed. If
2504
+ items have only been added to the array, it performs a $pushAll. If items
2505
+ have only been removed, it performs a $pullAll. If both additions and
2506
+ removals have occurred it performs a $set to avoid conflicting mods.
2507
+
2508
+ ### Resolved Issues
2509
+
2510
+ * Calling `Document#as_document` on a frozen document on Rubinius returns the
2511
+ attributes instead of nil.
2512
+
2513
+ * \#1554 Split application of default values into proc/non-procs, where
2514
+ non-procs get executed immediately during instantiation, and procs get
2515
+ executed after all other values are set.
2516
+
2517
+ * \#1553 Combinations of adding and removing values from an array use a $set
2518
+ on the current contents of the array, not the new values.
2519
+
2520
+ * \#1546 Dirty changes should be returned in a hash with indifferent access.
2521
+
2522
+ * \#1542 Eager loading now respects the options (ie skip, limit) provided to
2523
+ the criteria when fetch the associations.
2524
+
2525
+ * \#1530 Don't duplicate added values to arrays via dirty tracking if the
2526
+ array is a foreign key field.
2527
+
2528
+ * \#1529 Calling `unscoped` on relational associations now works properly.
2529
+
2530
+ * \#1524 Allow access to relations in overridden field setters by pre-setting
2531
+ foreign key default values.
2532
+
2533
+ * \#1523 Allow disabling of observers via `disable`. (Jonas Schneider)
2534
+
2535
+ * \#1522 Fixed create indexes rake task for Rails 3.2. (Gray Manley)
2536
+
2537
+ * \#1517 Fix Mongoid documents to properly work with RSpec's stub_model.
2538
+ (Tiago Rafael Godinho)
2539
+
2540
+ * \#1516 Don't duplicate relational many documents on bind.
2541
+
2542
+ * \#1515 Mongoid no longer attempts to serialize custom fields on complex
2543
+ criteria by default.
2544
+
2545
+ * \#1503 Has many relation substitution now handles any kind of mix of existing
2546
+ and new docs.
2547
+
2548
+ * \#1502 Nested attributes on embedded documents respects if the child is
2549
+ paranoid.
2550
+
2551
+ * \#1497 Use provided message on failing uniqueness validation. (Justin Etheredge)
2552
+
2553
+ * \#1491 Return nil when no default set on localized fields. (Tiago Rafael Godinho)
2554
+
2555
+ * \#1483 Sending module includes at runtime which add new fields to a parent
2556
+ document, also have the fields added to subclasses.
2557
+
2558
+ * \#1482 Applying new sorting options does not merge into previously
2559
+ chained criteria. (Gerad Suyderhoud)
2560
+
2561
+ * \#1481 Fix invalid query when accessing many-to-many relations before
2562
+ defaults are set.
2563
+
2564
+ * \#1480 Mongoid's internal serialized field types renamespaced to Internal in order
2565
+ to not conflict with ruby core classes in custom serializable types.
2566
+
2567
+ * \#1479 Don't duplicate ids on many-to-many when using create or create!
2568
+
2569
+ * \#1469 When extract_id returns nil, get the document out of the identity map
2570
+ by the criteria selector.
2571
+
2572
+ * \#1467 Defining a field named metadata now properly raises an invalid field
2573
+ error.
2574
+
2575
+ * \#1463 Batch insert consumers are now scoped to collection to avoid persistence
2576
+ of documents to other collections in callbacks going to the wrong place.
2577
+
2578
+ * \#1462 Assigning has many relations via nested attribtues `*_attributes=` does
2579
+ not autosave the relation.
2580
+
2581
+ * \#1461 Fixed serialization of foreign key fields in complex criteria not to
2582
+ escape the entire hash.
2583
+
2584
+ * \#1458 Versioning no longer skips fields that have been protected from mass
2585
+ assignment.
2586
+
2587
+ * \#1455, \#1456 Calling destroy on any document now temporarily marks it as
2588
+ flagged for destroy until the operation is complete. (Nader Akhnoukh)
2589
+
2590
+ * \#1453 `Model#to_key` should return a value when the document is destroyed.
2591
+
2592
+ * \#1449 New documents no longer get persisted when replaced on a has one as
2593
+ a side effect. (jasonsydes)
2594
+
2595
+ * \#1439 embedded? should return true when relation defined as cyclic.
2596
+
2597
+ * \#1433 Polymorphic nested attributes for embedded and relational 1-1 now
2598
+ update properly.
2599
+
2600
+ * \#1426 Frozen documents can now be cloned. (aagrawal2001)
2601
+
2602
+ * \#1382 Raise proper error when creating indexes via rake task if index
2603
+ definition is incorrect. (Mathieu Ravaux)
2604
+
2605
+ * \#1381, \#1371 The identity map now functions properly with inherited
2606
+ documents. (Paul Canavese)
2607
+
2608
+ * \#1370 Split concat on embedded arrays into its own method to handle the
2609
+ batch processing due to after callback run execution issues.
2610
+
2611
+ * \#1366 Array and hash values now get deep copied for dirty tracking.
2612
+
2613
+ * \#1359 Provide ability to not have default scope applied to all named
2614
+ scopes via using lambdas.
2615
+
2616
+ * \#1333 Fixed errors with custom types that exist in namespaces. (Peter Gumeson)
2617
+
2618
+ * \#1259 Default values are treated as dirty if they differ from the database
2619
+ state.
2620
+
2621
+ * \#1255 Ensure embedded documents respect the defined default scope.
2622
+
2623
+ ## 2.3.4
2624
+
2625
+ * \#1445 Prevent duplicate documents in the loaded array on the target
2626
+ enumerable for relational associations.
2627
+
2628
+ * \#1442 When using create_ methods for has one relations, the appropriate
2629
+ destructive methods now get called when replacing an existing document.
2630
+
2631
+ * \#1431 Enumerable context should add to the loaded array post yield, so
2632
+ that methods like #any? that short circuit based on the value of the block
2633
+ dont falsely have extra documents.
2634
+
2635
+ * \#1418 Documents being loaded from the database for revision purposes
2636
+ no longer get placed in the identity map.
2637
+
2638
+ * \#1399 Allow conversion of strings to integers in foreign keys where the
2639
+ id is defined as an int.
2640
+
2641
+ * \#1397 Don't add default sorting criteria on first if they sort criteria
2642
+ already exists.
2643
+
2644
+ * \#1394 Fix exists? to work when count is greater than 1. (Nick Hoffman)
2645
+
2646
+ * \#1392 Return 0 on aggregation functions where field is nonexistant.
2647
+
2648
+ * \#1391 Uniqueness validation now works properly on embedded documents that are
2649
+ using primary key definitions.
2650
+
2651
+ * \#1390 When _type field is lower case class camelize before constantizing.
2652
+
2653
+ * \#1383 Fix cast on read for serializable fields that are subclassed.
2654
+
2655
+ * \#1357 Delayed atomic sets from update_attributes on embedded documents
2656
+ multiple levels deep now properly persist.
2657
+
2658
+ * \#1326 Ensure base document on HABTM gets its keys saved after saving a newly
2659
+ build child document.
2660
+
2661
+ * \#1301 Don't overwrite base metadata on embedded in relations if already set.
2662
+
2663
+ * \#1221 HABTM with inverse nil is allowed again on embedded documents.
2664
+
2665
+ * \#1208 Don't auto-persist child documents via the setter when setting from
2666
+ an embedded_in.
2667
+
2668
+ * \#791 Root document updates its timestamps when only embedded documents have
2669
+ changed.
2670
+
2671
+ ## 2.3.3
2672
+
2673
+ ### Resolved Issues
2674
+
2675
+ * \#1386 Lowered mongo/bson dependency to 1.3
2676
+
2677
+ * \#1377 Fix aggregation functions to properly handle nil or indefined values.
2678
+ (Maxime Garcia)
2679
+
2680
+ * \#1373 Warn if a scope overrides another scope.
2681
+
2682
+ * \#1372 Never persist when binding inside of a read attribute for validation.
2683
+
2684
+ * \#1364 Fixed reloading of documents with non bson object id ids.
2685
+
2686
+ * \#1360 Fixed performance of Mongoid's observer instantiation by hooking into
2687
+ Active Support's load hooks, a la AR.
2688
+
2689
+ * \#1358 Fixed type error on many to many synchronization when inverse_of is
2690
+ set to nil.
2691
+
2692
+ * \#1356 $in criteria can now be chained to non-complex criteria on the same
2693
+ key without error.
2694
+
2695
+ * \#1350, \#1351 Fixed errors in the string conversions of double quotes and
2696
+ tilde when paramterizing keys.
2697
+
2698
+ * \#1349 Mongoid documents should not blow up when including Enumerable.
2699
+ (Jonas Nicklas)
2700
+
2701
+ ## 2.3.2
2702
+
2703
+ ### Resolved Issues
2704
+
2705
+ * \#1347 Fix embedded matchers when provided a hash value that does not have a
2706
+ modifier as a key.
2707
+
2708
+ * \#1346 Dup default sorting criteria when calling first/last on a criteria.
2709
+
2710
+ * \#1343 When passing no arguments to `Criteria#all_of` return all documents.
2711
+ (Chris Leishman)
2712
+
2713
+ * \#1339 Ensure destroy callbacks are run on cascadable children when deleting via
2714
+ nested attributes.
2715
+
2716
+ * \#1324 Setting `inverse_of: nil` on a many-to-many referencing the same class
2717
+ returns nil for the inverse foreign key.
2718
+
2719
+ * \#1323 Allow both strings and symbols as ids in the attributes array for
2720
+ nested attributes. (Michael Wood)
2721
+
2722
+ * \#1312 Setting a logger on the config now accepts anything that quacks like a
2723
+ logger.
2724
+
2725
+ * \#1297 Don't hit the database when accessing relations if the base is new.
2726
+
2727
+ * \#1239 Allow appending of referenced relations in create blocks, post default set.
2728
+
2729
+ * \#1236 Ensure all models are loaded in rake tasks, so even in threadsafe mode
2730
+ all indexes can be created.
2731
+
2732
+ * \#736 Calling #reload on embedded documents now works properly.
2733
+
2734
+ ## 2.3.1
2735
+
2736
+ ### Resolved Issues
2737
+
2738
+ * \#1338 Calling #find on a scope or relation checks that the document in the
2739
+ identity map actually matches other scope parameters.
2740
+
2741
+ * \#1321 HABTM no longer allows duplicate entries or keys, instead of the previous
2742
+ inconsistencies.
2743
+
2744
+ * \#1320 Fixed errors in perf benchmark.
2745
+
2746
+ * \#1316 Added a separate Rake task "db:mongoid:drop" so Mongoid and AR can coexist.
2747
+ (Daniel Vartanov)
2748
+
2749
+ * \#1311 Fix issue with custom field serialization inheriting from hash.
2750
+
2751
+ * \#1310 The referenced many enumerable target no longer duplicates loaded and
2752
+ added documents when the identity map is enabled.
2753
+
2754
+ * \#1295 Fixed having multiple includes only execute the eager loading of the first.
2755
+
2756
+ * \#1287 Fixed max versions limitation with versioning.
2757
+
2758
+ * \#1277 attribute_will_change! properly flags the attribute even if no change occured.
2759
+
2760
+ * \#1063 Paranoid documents properly run destroy callbacks on soft destroy.
2761
+
2762
+ * \#1061 Raise `Mongoid::Errors::InvalidTime` when time serialization fails.
2763
+
2764
+ * \#1002 Check for legal bson ids when attempting conversion.
2765
+
2766
+ * \#920 Allow relations to be named target.
2767
+
2768
+ * \#905 Return normalized class name in metadata if string was defined with a
2769
+ prefixed ::.
2770
+
2771
+ * \#861 accepts_nested_attributes_for is no longer needed to set embedded documents
2772
+ via a hash or array of hashes directly.
2773
+
2774
+ * \#857 Fixed cascading of dependent relations when base document is paranoid.
2775
+
2776
+ * \#768 Fixed class_attribute definitions module wide.
2777
+
2778
+ * \#408 Embedded documents can now be soft deleted via `Mongoid::Paranoia`.
2779
+
2780
+ ## 2.3.0
2781
+
2782
+ ### New Features
2783
+
2784
+ * Mongoid now supports basic localized fields, storing them under the covers as a
2785
+ hash of locale => value pairs. `field :name, localize: true`
2786
+
2787
+ * \#1275 For applications that default safe mode to true, you can now tell a
2788
+ single operation to persist without safe mode via #unsafely:
2789
+ `person.unsafely.save`, `Person.unsafely.create`. (Matt Sanders)
2790
+
2791
+ * \#1256 Mongoid now can create indexes for models in Rails engines. (Caio Filipini)
2792
+
2793
+ * \#1228 Allow pre formatting of compsoite keys by passing a block to #key.
2794
+ (Ben Hundley)
2795
+
2796
+ * \#1222 Scoped mass assignment is now supported. (Andrew Shaydurov)
2797
+
2798
+ * \#1196 Timestamps can now be turned off on a call-by-call basis via the use
2799
+ of #timeless: `person.timeless.save`, `Person.timeless.create(:title => "Sir")`.
2800
+
2801
+ * \#1103 Allow developers to create their own custom complex criteria. (Ryan Ong)
2802
+
2803
+ * Mongoid now includes all defined fields in `serializable_hash` and `to_json`
2804
+ results even if the fields have no values to make serialized documents easier
2805
+ to use by ActiveResource clients.
2806
+
2807
+ * Support for MongoDB's $and operator is now available in the form of:
2808
+ `Criteria#all_of(*args)` where args is multiple hash expressions.
2809
+
2810
+ * \#1250, \#1058 Embedded documents now can have their callbacks fired on a parent
2811
+ save by setting `:cascade_callbacks => true` on the relation.
2812
+ (pyromanic, Paul Rosania, Jak Charlton)
2813
+
2814
+ ### Major Changes
2815
+
2816
+ * Mongoid now depends on Active Model 3.1 and higher.
2817
+
2818
+ * Mongoid now depends on the Mongo Ruby Driver 1.4 and higher.
2819
+
2820
+ * Mongoid requires MongoDB 2.0.0 and higher.
2821
+
2822
+ ### Resolved Issues
2823
+
2824
+ * \#1308 Fixed scoping of HABTM finds.
2825
+
2826
+ * \#1300 Namespaced models should handle recursive embedding properly.
2827
+
2828
+ * \#1299 Self referenced documents with versioning no longer fail when inverse_of
2829
+ is not defined on all relations.
2830
+
2831
+ * \#1296 Renamed internal building method to _building.
2832
+
2833
+ * \#1288, \#1289 _id and updated_at should not be part of versioned attributes.
2834
+
2835
+ * \#1273 Mongoid.preload_models now checks if preload configuration option is set,
2836
+ where Mongoid.load_models always loads everything. (Ryan McGeary)
2837
+
2838
+ * \#1244 Has one relations now adhere to default dependant behaviour.
2839
+
2840
+ * \#1225 Fixed delayed persistence of embedded documents via $set.
2841
+
2842
+ * \#1166 Don't load config in Railtie if no env variables defined. (Terence Lee)
2843
+
2844
+ * \#1052 `alias_attribute` now works again as expected.
2845
+
2846
+ * \#939 Apply default attributes when upcasting via #becomes. (Christos Pappas)
2847
+
2848
+ * \#932 Fixed casting of integer fields with leading zeros.
2849
+
2850
+ * \#948 Reset version number on clone if versions existed.
2851
+
2852
+ * \#763 Don't merge $in criteria arrays when chaining named scopes.
2853
+
2854
+ * \#730 Existing models that have relations added post persistence of originals
2855
+ can now have new relations added with no migrations.
2856
+
2857
+ * \#726 Embedded documents with compound keys not validate uniqueness correctly.
2858
+
2859
+ * \#582 Cyclic non embedded relations now validate uniqueness correctly.
2860
+
2861
+ * \#484 Validates uniqueness with multiple scopes of all types now work properly.
2862
+
2863
+ * Deleting versions created with `Mongoid::Versioning` no longer fires off
2864
+ dependent cascading on relations.
2865
+
2866
+ ## 2.2.5
2867
+
2868
+ * This was a small patch release to address 2.2.x Heroku errors during asset
2869
+ compilation.
2870
+
2871
+ ## 2.2.4
2872
+
2873
+ * \#1377 Fix aggregation functions to properly handle nil or indefined values.
2874
+ (Maxime Garcia)
2875
+
2876
+ * \#1373 Warn if a scope overrides another scope.
2877
+
2878
+ * \#1372 Never persist when binding inside of a read attribute for validation.
2879
+
2880
+ * \#1358 Fixed type error on many to many synchronization when inverse_of is
2881
+ set to nil.
2882
+
2883
+ * \#1356 $in criteria can now be chained to non-complex criteria on the same
2884
+ key without error.
2885
+
2886
+ * \#1350, \#1351 Fixed errors in the string conversions of double quotes and
2887
+ tilde when paramterizing keys.
2888
+
2889
+ * \#1349 Mongoid documents should not blow up when including Enumerable.
2890
+ (Jonas Nicklas)
2891
+
2892
+ ## 2.2.3
2893
+
2894
+ * \#1295 Fixed having multiple includes only execute the eager loading of the first.
2895
+
2896
+ * \#1225 Fixed delayed persistence of embedded documents via $set.
2897
+
2898
+ * \#1002 Fix BSON object id conversion to check if legal first.
2899
+
2900
+ ## 2.2.2
2901
+
2902
+ * This release removes the restriction of a dependency on 1.3.x of the mongo
2903
+ ruby driver. Users may now use 1.3.x through 1.4.x.
2904
+
2905
+ ## 2.2.1
2906
+
2907
+ ### Resolved Issues
2908
+
2909
+ * \#1210, \#517 Allow embedded document relation queries to use dot notation.
2910
+ (Scott Ellard)
2911
+
2912
+ * \#1198 Enumerable target should use criteria count if loaded has no docs.
2913
+
2914
+ * \#1164 Get rid of remaining no method in_memory errors.
2915
+
2916
+ * \#1070 Allow custom field serializers to have their own constructors.
2917
+
2918
+ * \#1176 Allow access to parent documents from embedded docs in after_destroy
2919
+ callbacks.
2920
+
2921
+ * \#1191 Context group methods (min, max, sum) no longer return NaN but instead
2922
+ return nil if field doesn't exist or have values.
2923
+
2924
+ * \#1193, \#1271 Always return Integers for integer fields with .000 precisions,
2925
+ not floats.
2926
+
2927
+ * \#1199 Fixed performance issues of hash and array field access when reading
2928
+ multiple times.
2929
+
2930
+ * \#1218 Fixed issues with relations referencing models with integer foreign keys.
2931
+
2932
+ * \#1219 Fixed various conflicting modifications issues when pushing and pulling
2933
+ from the same embedded document in a single call.
2934
+
2935
+ * \#1220 Metadata should not get overwritten by nil on binding.
2936
+
2937
+ * \#1231 Renamed Mongoid's atomic set class to Sets to avoid conflicts with Ruby's
2938
+ native Set after document inclusion.
2939
+
2940
+ * \#1232 Fix access to related models during before_destroy callbacks when
2941
+ cascading.
2942
+
2943
+ * \#1234 Fixed HABTM foreign key synchronization issues when destroying
2944
+ documents.
2945
+
2946
+ * \#1243 Polymorphic relations dont convert to object ids when querying if the
2947
+ ids are defined as strings.
2948
+
2949
+ * \#1247 Force Model.first to sort by ascending id to guarantee first document.
2950
+
2951
+ * \#1248 Added #unscoped to embedded many relations.
2952
+
2953
+ * \#1249 Destroy flags in nested attributes now actually destroy the document
2954
+ for has_many instead of just breaking the relation.
2955
+
2956
+ * \#1272 Don't modify configuration options in place when creating replica set
2957
+ connections.
2958
+
2959
+ ## 2.2.0
2960
+
2961
+ ### New Features
2962
+
2963
+ * Mongoid now contains eager loading in the form of `Criteria#includes(*args)`.
2964
+ This works on has_one, has_many, belongs_to associations and requires the identity map to
2965
+ be enabled in order to function. Set `identity_map_enabled: true` in your
2966
+ `mongoid.yml`. Ex: `Person.where(title: "Sir").includes(:posts, :game)`
2967
+
2968
+ * Relations can now take a module as a value to the `:extend` option. (Roman
2969
+ Shterenzon)
2970
+
2971
+ * Capped collections can be created by passing the options to the `#store_in`
2972
+ macro: `Person.store_in :people, capped: true, max: 1000000`
2973
+
2974
+ * Mongoid::Collection now supports `collection.find_and_modify`
2975
+
2976
+ * `Document#has_attribute?` now aliases to `Document#attribute_present?`
2977
+
2978
+ * \#930 You can now turn off the Mongoid logger via the mongoid.yml by
2979
+ doing `logger: false`
2980
+
2981
+ * \#909 We now raise a `Mongoid::Errors::Callback` exception if persisting with
2982
+ a bang method and a callback returns false, instead of the uninformative
2983
+ validations error from before.
2984
+
2985
+ ### Major Changes
2986
+
2987
+ * \#1173 has_many relations no longer delete all documents on a set of the relation
2988
+ (= [ doc_one, doc_two ]) but look to the dependent option to determine what
2989
+ behaviour should occur. :delete and :destroy will behave as before, :nullify and
2990
+ no option specified will both nullify the old documents without deleting.
2991
+
2992
+ * \#1142, \#767 Embedded relations no longer immediately persist atomically
2993
+ when accessed via a parent attributes set. This includes nested attributes setting
2994
+ and `attributes=` or `write_attributes`. The child changes then remain dirty and
2995
+ atomically update when save is called on them or the parent document.
2996
+
2997
+ ### Resolved Issues
2998
+
2999
+ * \#1190 Fixed the gemspec errors due to changing README and CHANGELOG to markdown.
3000
+
3001
+ * \#1180, \#1084, \#955 Mongoid now checks the field types rather than if the name
3002
+ contains `/id/` when trying to convert to object ids on criteria.
3003
+
3004
+ * \#1176 Enumerable targets should always return the in memory documents first,
3005
+ when calling `#first`
3006
+
3007
+ * \#1175 Make sure both sides of many to many relations are in sync during a create.
3008
+
3009
+ * \#1172 Referenced enumerable relations now properly handle `#to_json`
3010
+ (Daniel Doubrovkine)
3011
+
3012
+ * \#1040 Increased performance of class load times by removing all delegate calls
3013
+ to self.class.
3014
+
3015
+ ## 2.1.9
3016
+
3017
+ ### Resolved Issues
3018
+
3019
+ * \#1159 Fixed build blocks not to cancel out each other when nested.
3020
+
3021
+ * \#1154 Don't delete many-to-many documents on empty array set.
3022
+
3023
+ * \#1153 Retain parent document reference in after callbacks.
3024
+
3025
+ * \#1151 Fix associated validation infinite loop on self referencing documents.
3026
+
3027
+ * \#1150 Validates associated on `belongs_to` is `false` by default.
3028
+
3029
+ * \#1149 Fixed metadata setting on `belongs_to` relations.
3030
+
3031
+ * \#1145 Metadata inverse should return `nil` if `inverse_of` was set as `nil`.
3032
+
3033
+ * \#1139 Enumerable targets now quack like arrays.
3034
+
3035
+ * \#1136 Setting `belongs_to` parent to `nil` no longer deletes the parent.
3036
+
3037
+ * \#1120 Don't call `in_memory` on relations if they don't respond to it.
3038
+
3039
+ * \#1075 Set `self` in default procs to the document instance.
3040
+
3041
+ * \#1072 Writing attributes for nested documents can take a hash or array of hashes.
3042
+
3043
+ * \#990 Embedded documents can use a single `embedded_in` with multiple parent definitions.
3044
+
3045
+ ## 2.1.8
3046
+
3047
+ ### Resolved Issues
3048
+
3049
+ * \#1148 Fixed `respond_to?` on all relations to return properly.
3050
+
3051
+ * \#1146 Added back the Mongoid destructive fields check when defining fields.
3052
+
3053
+ * \#1141 Fixed conversions of `nil` values in criteria.
3054
+
3055
+ * \#1131 Verified Mongoid/Kaminari paginating correctly.
3056
+
3057
+ * \#1105 Fixed atomic update consumer to be scoped to class.
3058
+
3059
+ * \#1075 `self` in default lambdas and procs now references the document instance.
3060
+
3061
+ * \#740 Removed `embedded_object_id` configuration parameter.
3062
+
3063
+ * \#661 Fixed metadata caching on embedded documents.
3064
+
3065
+ * \#595 Fixed relation reload flagging.
3066
+
3067
+ * \#410 Moving documents from one relation to another now works as expected.
3068
+
3069
+ ## 2.1.7
3070
+
3071
+ This was a specific release to fix MRI 1.8.7 breakages introduced by 2.1.6.
3072
+
3073
+ ## 2.1.6
3074
+
3075
+ ### Resolved Issues
3076
+
3077
+ * \#1126 Fix setting of relations with other relation proxies.
3078
+
3079
+ * \#1122 Hash and array fields now properly flag as dirty on access and change.
3080
+
3081
+ * \#656 Fixed reload breaking relations on unsetting of already loaded associations.
3082
+
3083
+ * \#647 Prefer `#unset` to `#remove_attribute` for removing values.
3084
+
3085
+ * \#290 Verify pushes into deeply embedded documents.
3086
+
3087
+ ## 2.1.5
3088
+
3089
+ ### Resolved Issues
3090
+
3091
+ * \#1116 Embedded children retain reference to parent in destroy callbacks.
3092
+
3093
+ * \#1110, \#1115 Don't memoize metadata related helpers on documents.
3094
+
3095
+ * \#1112 `db:create_indexes` no longer indexes subclasses multiple times.
3096
+
3097
+ * \#1111, \#1098 Don't set `_id` in `$set` operations.
3098
+
3099
+ * \#1007 Update attribute properly tracks array changes.
3100
+
3101
+ ## 2.1.4
3102
+
3103
+ This was a specific release to get a Psych generated gemspec so no more parse errors would occur on those rubies that were using the new YAML parser.
3104
+
3105
+ ## 2.1.3
3106
+
3107
+ ### Resolved Issues
3108
+
3109
+ * \#1109 Fixed validations not loading one to ones into memory.
3110
+
3111
+ * \#1107 Mongoid no longer wants required `mongoid/railtie` in `application.rb`.
3112
+
3113
+ * \#1102 Fixed nested attributes deletion.
3114
+
3115
+ * \#1097 Reload now runs `after_initialize` callbacks.
3116
+
3117
+ * \#1079 Embeds many no longer duplicates documents.
3118
+
3119
+ * \#1078 Fixed array criteria matching on embedded documents.
3120
+
3121
+ * \#1028 Implement scoped on one-to-many and many-to-many relations.
3122
+
3123
+ * \#988 Many-to-many clear no longer deletes the child documents.
3124
+
3125
+ * \#977 Autosaving relations works also through nested attributes.
3126
+
3127
+ * \#972 Recursive embedding now handles namespacing on generated names.
3128
+
3129
+ * \#943 Don't override `Document#attributes`.
3130
+
3131
+ * \#893 Verify count is not caching on many to many relations.
3132
+
3133
+ * \#815 Verify `after_initialize` is run in the correct place.
3134
+
3135
+ * \#793 Verify `any_of` scopes chain properly with any other scope.
3136
+
3137
+ * \#776 Fixed mongoid case quality when dealing with subclasses.
3138
+
3139
+ * \#747 Fixed complex criteria using its keys to render its string value.
3140
+
3141
+ * \#721 `#safely` now properly raises validation errors when they occur.
3142
+
3143
+ ## 2.1.2
3144
+
3145
+ ### Resolved Issues
3146
+
3147
+ * \#1082 Alias `size` and `length` to `count` on criteria. (Adam Greene)
3148
+
3149
+ * \#1044 When multiple relations are defined for the same class, always return the default inverse first if `inverse_of` is not defined.
3150
+
3151
+ * \#710 Nested attributes accept both `id` and `_id` in hashes or arrays.
3152
+
3153
+ * \#1047 Ignore `nil` values passed to `embeds_man` pushes and substitution. (Derick Bailey)
3154
+
3155
+ ## 2.1.1
3156
+
3157
+ ### Resolved Issues
3158
+
3159
+ * \#1021, \#719 Many to many relations dont trigger extra database queries when pushing new documents.
3160
+
3161
+ * \#607 Calling `create` on large associations does not load the entire relation.
3162
+
3163
+ * \#1064 `Mongoid::Paranoia` should respect `unscoped` and `scoped`.
3164
+
3165
+ * \#1026 `model#update_attribute` now can update booleans to `false`.
3166
+
3167
+ * \#618 Crack XML library breaks Mongoid by adding `#attributes` method to the `String` class. (Stephen McGinty)
3168
+
3169
+ ## 2.1.0
3170
+
3171
+ ### Major Changes
3172
+
3173
+ * Mongoid now requires MongoDB 1.8.x in order to properly support the `#bit` and `#rename` atomic operations.
3174
+
3175
+ * Traditional slave support has been removed from Mongoid. Replica sets should be used in place of traditional master and slave setups.
3176
+
3177
+ * Custom field serialization has changed. Please see [serializable](https://github.com/mongoid/mongoid/blob/master/lib/mongoid/fields/serializable.rb) for changes.
3178
+
3179
+ * The dirty attribute tracking has been switched to use ActiveModel, this brings many bug fixes and changes:
3180
+
3181
+ * \#756 After callbacks and observers see what was changed instead of changes just made being in previous_changes
3182
+
3183
+ * \#434 Documents now are flagged as dirty when brand new or the state on instantiation differs from the database state. This is consistent with ActiveRecord.
3184
+
3185
+ * \#323 Mongoid now supports [field]_will_change! from ActiveModel::Dirty
3186
+
3187
+ * Mongoid model preloading in development mode now defaults to `false`.
3188
+
3189
+ * `:autosave => true` on relational associations now saves on update as well as create.
3190
+
3191
+ * Mongoid now has an identity map for simple `find_by_id` queries. See the website for documentation.
3192
+
3193
+ ### New Features
3194
+
3195
+ * \#1067 Fields now accept a `:versioned` attribute to be able to disable what fields are versioned with `Mongoid::Versioning`. (Jim Benton)
3196
+
3197
+ * \#587 Added order preference to many and many to many associations. (Gregory Man)
3198
+
3199
+ * Added ability to chain `order_by` statements. (Gregory Man)
3200
+
3201
+ * \#961 Allow arbitrary `Mongo::Connection` options to pass through `Mongoid::Config::Database` object. (Morgan Nelson)
3202
+
3203
+ * Enable `autosave` for many to many references. (Dave Krupinski)
3204
+
3205
+ * The following explicit atomic operations have been added: `Model#bit`, `Model#pop`, `Model#pull`, `Model#push_all`, `Model#rename`, `Model#unset`.
3206
+
3207
+ * Added exception translations for Hindi. (Sukeerthi Adiga)
3208
+
3209
+ ### Resolved Issues
3210
+
3211
+ * \#974 Fix `attribute_present?` to work correctly then attribute value is `false`, thanks to @nickhoffman. (Gregory Man)
3212
+
3213
+ * \#960 create indexes rake task is not recognizing a lot of mongoid models because it has problems guessing their model names from filenames. (Tobias Schlottke)
3214
+
3215
+ * \#874 Deleting from a M-M reference is one-sided. (nickhoffman, davekrupinski)
3216
+
3217
+ * Replace deprecated `class_inheritable_hash` dropped in Rails 3.1+. (Konstantin Shabanov)
3218
+
3219
+ * Fix inconsistent state when replacing an entire many to many relation.
3220
+
3221
+ * Don't clobber inheritable attributes when adding subclass field inheritance. (Dave Krupinski)
3222
+
3223
+ * \#914 Querying embedded documents with `$or` selector. (Max Golovnia)
3224
+
3225
+ * \#514 Fix marshaling of documents with relation extensions. (Chris Griego)
3226
+
3227
+ * `Metadata#extension` now returns a `Module`, instead of a `Proc`, when an extension is defined.
3228
+
3229
+ * \#837 When `allow_dynamic_fields` is set to `false` and loading an embedded document with an unrecognized field, an exception is raised.
3230
+
3231
+ * \#963 Initializing array of embedded documents via hash regressed (Chris Griego, Morgan Nelson)
3232
+
3233
+ * `Mongoid::Config.reset` resets the options to their default values.
3234
+
3235
+ * `Mongoid::Fields.defaults` is memoized for faster instantiation of models.