sepastian-mongoid-rails4 4.0.0.alpha

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