mongoid 6.4.8 → 7.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +0 -26
  5. data/lib/config/locales/en.yml +17 -21
  6. data/lib/mongoid.rb +2 -2
  7. data/lib/mongoid/association.rb +150 -0
  8. data/lib/mongoid/association/accessors.rb +339 -0
  9. data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
  10. data/lib/mongoid/association/builders.rb +92 -0
  11. data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
  12. data/lib/mongoid/association/depending.rb +116 -0
  13. data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
  14. data/lib/mongoid/association/embedded.rb +4 -0
  15. data/lib/mongoid/{relations → association}/embedded/batchable.rb +27 -53
  16. data/lib/mongoid/association/embedded/cyclic.rb +109 -0
  17. data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
  18. data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
  19. data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
  20. data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
  21. data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
  22. data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
  23. data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
  24. data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
  25. data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
  26. data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
  27. data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
  28. data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
  29. data/lib/mongoid/association/macros.rb +204 -0
  30. data/lib/mongoid/{relations → association}/many.rb +18 -52
  31. data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
  32. data/lib/mongoid/association/nested.rb +15 -0
  33. data/lib/mongoid/association/nested/many.rb +200 -0
  34. data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
  35. data/lib/mongoid/association/nested/one.rb +127 -0
  36. data/lib/mongoid/{relations → association}/one.rb +6 -6
  37. data/lib/mongoid/association/options.rb +152 -0
  38. data/lib/mongoid/{relations → association}/proxy.rb +31 -58
  39. data/lib/mongoid/association/referenced.rb +7 -0
  40. data/lib/mongoid/association/referenced/auto_save.rb +79 -0
  41. data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
  42. data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
  43. data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
  44. data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
  45. data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
  46. data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
  47. data/lib/mongoid/association/referenced/eager.rb +159 -0
  48. data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
  49. data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
  50. data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
  51. data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
  52. data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
  53. data/lib/mongoid/association/referenced/has_many.rb +273 -0
  54. data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
  55. data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
  56. data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
  57. data/lib/mongoid/association/referenced/has_many/enumerable.rb +479 -0
  58. data/lib/mongoid/association/referenced/has_many/proxy.rb +577 -0
  59. data/lib/mongoid/association/referenced/has_one.rb +204 -0
  60. data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
  61. data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
  62. data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
  63. data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
  64. data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
  65. data/lib/mongoid/association/referenced/syncable.rb +170 -0
  66. data/lib/mongoid/{relations → association}/reflections.rb +21 -17
  67. data/lib/mongoid/association/relatable.rb +415 -0
  68. data/lib/mongoid/association/touchable.rb +97 -0
  69. data/lib/mongoid/atomic.rb +6 -6
  70. data/lib/mongoid/atomic/modifiers.rb +8 -12
  71. data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
  72. data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
  73. data/lib/mongoid/attributes.rb +2 -1
  74. data/lib/mongoid/attributes/nested.rb +10 -10
  75. data/lib/mongoid/attributes/processing.rb +2 -2
  76. data/lib/mongoid/attributes/readonly.rb +2 -4
  77. data/lib/mongoid/clients.rb +0 -2
  78. data/lib/mongoid/clients/options.rb +1 -1
  79. data/lib/mongoid/clients/storage_options.rb +0 -1
  80. data/lib/mongoid/composable.rb +3 -4
  81. data/lib/mongoid/config.rb +1 -0
  82. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  83. data/lib/mongoid/contextual/atomic.rb +3 -6
  84. data/lib/mongoid/contextual/map_reduce.rb +3 -7
  85. data/lib/mongoid/contextual/memory.rb +5 -10
  86. data/lib/mongoid/contextual/mongo.rb +10 -27
  87. data/lib/mongoid/copyable.rb +6 -6
  88. data/lib/mongoid/criteria.rb +1 -2
  89. data/lib/mongoid/criteria/includable.rb +14 -14
  90. data/lib/mongoid/criteria/modifiable.rb +8 -14
  91. data/lib/mongoid/criteria/queryable/mergeable.rb +1 -3
  92. data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
  93. data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
  94. data/lib/mongoid/document.rb +6 -6
  95. data/lib/mongoid/errors.rb +3 -1
  96. data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
  97. data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
  98. data/lib/mongoid/errors/unknown_model.rb +25 -0
  99. data/lib/mongoid/extensions/array.rb +5 -5
  100. data/lib/mongoid/extensions/big_decimal.rb +1 -1
  101. data/lib/mongoid/extensions/object.rb +4 -4
  102. data/lib/mongoid/extensions/range.rb +1 -0
  103. data/lib/mongoid/extensions/regexp.rb +0 -1
  104. data/lib/mongoid/extensions/string.rb +1 -3
  105. data/lib/mongoid/factory.rb +4 -3
  106. data/lib/mongoid/fields.rb +1 -1
  107. data/lib/mongoid/fields/foreign_key.rb +5 -5
  108. data/lib/mongoid/fields/standard.rb +2 -14
  109. data/lib/mongoid/fields/validators/macro.rb +1 -1
  110. data/lib/mongoid/indexable.rb +8 -5
  111. data/lib/mongoid/interceptable.rb +5 -5
  112. data/lib/mongoid/matchable.rb +0 -3
  113. data/lib/mongoid/persistable.rb +4 -5
  114. data/lib/mongoid/persistable/creatable.rb +2 -4
  115. data/lib/mongoid/persistable/deletable.rb +9 -10
  116. data/lib/mongoid/persistable/destroyable.rb +5 -1
  117. data/lib/mongoid/persistable/incrementable.rb +1 -1
  118. data/lib/mongoid/persistable/logical.rb +1 -1
  119. data/lib/mongoid/persistable/settable.rb +5 -5
  120. data/lib/mongoid/persistable/updatable.rb +2 -2
  121. data/lib/mongoid/persistable/upsertable.rb +1 -2
  122. data/lib/mongoid/persistence_context.rb +4 -9
  123. data/lib/mongoid/query_cache.rb +18 -65
  124. data/lib/mongoid/railtie.rb +0 -17
  125. data/lib/mongoid/reloadable.rb +1 -1
  126. data/lib/mongoid/scopable.rb +3 -3
  127. data/lib/mongoid/serializable.rb +3 -3
  128. data/lib/mongoid/tasks/database.rb +2 -3
  129. data/lib/mongoid/threaded.rb +0 -74
  130. data/lib/mongoid/traversable.rb +2 -2
  131. data/lib/mongoid/validatable.rb +8 -8
  132. data/lib/mongoid/validatable/presence.rb +2 -2
  133. data/lib/mongoid/validatable/uniqueness.rb +4 -4
  134. data/lib/mongoid/version.rb +1 -1
  135. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -4
  136. data/spec/app/models/animal.rb +2 -1
  137. data/spec/app/models/band.rb +0 -1
  138. data/spec/app/models/bomb.rb +1 -1
  139. data/spec/app/models/message.rb +1 -1
  140. data/spec/app/models/person.rb +5 -2
  141. data/spec/app/models/vertex.rb +6 -0
  142. data/spec/app/models/wiki_page.rb +1 -1
  143. data/spec/config/mongoid.yml +1 -0
  144. data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
  145. data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
  146. data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
  147. data/spec/mongoid/association/constrainable_spec.rb +115 -0
  148. data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
  149. data/spec/mongoid/association/depending_spec.rb +613 -0
  150. data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
  151. data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
  152. data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
  153. data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
  154. data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
  155. data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
  156. data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
  157. data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
  158. data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
  159. data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
  160. data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
  161. data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
  162. data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
  163. data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
  164. data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
  165. data/spec/mongoid/{relations → association}/macros_spec.rb +148 -93
  166. data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
  167. data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
  168. data/spec/mongoid/association/options_spec.rb +1321 -0
  169. data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
  170. data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
  171. data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
  172. data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
  173. data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
  174. data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
  175. data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
  176. data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
  177. data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
  178. data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
  179. data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
  180. data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
  181. data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
  182. data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +11 -11
  183. data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +1 -109
  184. data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
  185. data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
  186. data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
  187. data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
  188. data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
  189. data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
  190. data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
  191. data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
  192. data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
  193. data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
  194. data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
  195. data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
  196. data/spec/mongoid/atomic_spec.rb +17 -17
  197. data/spec/mongoid/attributes/nested_spec.rb +14 -12
  198. data/spec/mongoid/attributes/readonly_spec.rb +80 -125
  199. data/spec/mongoid/clients/factory_spec.rb +28 -52
  200. data/spec/mongoid/clients/options_spec.rb +65 -69
  201. data/spec/mongoid/config_spec.rb +24 -0
  202. data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
  203. data/spec/mongoid/contextual/mongo_spec.rb +4 -112
  204. data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
  205. data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
  206. data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
  207. data/spec/mongoid/criteria/queryable/selectable_spec.rb +6 -74
  208. data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
  209. data/spec/mongoid/criteria/scopable_spec.rb +0 -81
  210. data/spec/mongoid/criteria_spec.rb +16 -19
  211. data/spec/mongoid/document_spec.rb +2 -56
  212. data/spec/mongoid/extensions/array_spec.rb +11 -15
  213. data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
  214. data/spec/mongoid/extensions/object_spec.rb +7 -11
  215. data/spec/mongoid/extensions/range_spec.rb +7 -0
  216. data/spec/mongoid/extensions/regexp_spec.rb +0 -23
  217. data/spec/mongoid/extensions/string_spec.rb +7 -35
  218. data/spec/mongoid/factory_spec.rb +18 -11
  219. data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
  220. data/spec/mongoid/fields_spec.rb +2 -2
  221. data/spec/mongoid/findable_spec.rb +1 -1
  222. data/spec/mongoid/indexable_spec.rb +18 -8
  223. data/spec/mongoid/interceptable_spec.rb +21 -2
  224. data/spec/mongoid/matchable_spec.rb +1 -26
  225. data/spec/mongoid/persistable/deletable_spec.rb +0 -19
  226. data/spec/mongoid/persistable/destroyable_spec.rb +0 -19
  227. data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
  228. data/spec/mongoid/persistable/savable_spec.rb +3 -3
  229. data/spec/mongoid/persistable/settable_spec.rb +1 -35
  230. data/spec/mongoid/persistable/updatable_spec.rb +2 -2
  231. data/spec/mongoid/persistable_spec.rb +16 -16
  232. data/spec/mongoid/persistence_context_spec.rb +0 -14
  233. data/spec/mongoid/positional_spec.rb +10 -10
  234. data/spec/mongoid/query_cache_spec.rb +18 -87
  235. data/spec/mongoid/relations/proxy_spec.rb +124 -124
  236. data/spec/mongoid/scopable_spec.rb +0 -13
  237. data/spec/mongoid/threaded_spec.rb +0 -68
  238. data/spec/mongoid/validatable/associated_spec.rb +1 -1
  239. data/spec/mongoid/validatable/presence_spec.rb +7 -6
  240. data/spec/mongoid/validatable_spec.rb +1 -1
  241. data/spec/spec_helper.rb +7 -83
  242. metadata +586 -611
  243. metadata.gz.sig +2 -5
  244. data/lib/mongoid/clients/sessions.rb +0 -113
  245. data/lib/mongoid/errors/invalid_session_use.rb +0 -24
  246. data/lib/mongoid/matchable/nor.rb +0 -37
  247. data/lib/mongoid/railties/controller_runtime.rb +0 -86
  248. data/lib/mongoid/relations.rb +0 -148
  249. data/lib/mongoid/relations/accessors.rb +0 -267
  250. data/lib/mongoid/relations/auto_save.rb +0 -94
  251. data/lib/mongoid/relations/bindings.rb +0 -9
  252. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
  253. data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
  254. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
  255. data/lib/mongoid/relations/builder.rb +0 -57
  256. data/lib/mongoid/relations/builders.rb +0 -106
  257. data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
  258. data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
  259. data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
  260. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
  261. data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
  262. data/lib/mongoid/relations/cascading.rb +0 -56
  263. data/lib/mongoid/relations/cascading/delete.rb +0 -44
  264. data/lib/mongoid/relations/cascading/destroy.rb +0 -43
  265. data/lib/mongoid/relations/cascading/nullify.rb +0 -35
  266. data/lib/mongoid/relations/cascading/restrict.rb +0 -39
  267. data/lib/mongoid/relations/conversions.rb +0 -34
  268. data/lib/mongoid/relations/counter_cache.rb +0 -160
  269. data/lib/mongoid/relations/cyclic.rb +0 -107
  270. data/lib/mongoid/relations/eager/base.rb +0 -153
  271. data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
  272. data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
  273. data/lib/mongoid/relations/eager/has_many.rb +0 -38
  274. data/lib/mongoid/relations/eager/has_one.rb +0 -30
  275. data/lib/mongoid/relations/embedded/in.rb +0 -241
  276. data/lib/mongoid/relations/embedded/many.rb +0 -683
  277. data/lib/mongoid/relations/embedded/one.rb +0 -235
  278. data/lib/mongoid/relations/macros.rb +0 -367
  279. data/lib/mongoid/relations/metadata.rb +0 -1179
  280. data/lib/mongoid/relations/nested_builder.rb +0 -74
  281. data/lib/mongoid/relations/options.rb +0 -49
  282. data/lib/mongoid/relations/polymorphic.rb +0 -39
  283. data/lib/mongoid/relations/referenced/in.rb +0 -304
  284. data/lib/mongoid/relations/referenced/many.rb +0 -812
  285. data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
  286. data/lib/mongoid/relations/referenced/one.rb +0 -290
  287. data/lib/mongoid/relations/synchronization.rb +0 -169
  288. data/lib/mongoid/relations/targets.rb +0 -2
  289. data/lib/mongoid/relations/targets/enumerable.rb +0 -493
  290. data/lib/mongoid/relations/touchable.rb +0 -97
  291. data/spec/app/models/array_field.rb +0 -7
  292. data/spec/app/models/delegating_patient.rb +0 -16
  293. data/spec/integration/document_spec.rb +0 -22
  294. data/spec/mongoid/clients/sessions_spec.rb +0 -334
  295. data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
  296. data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
  297. data/spec/mongoid/matchable/nor_spec.rb +0 -209
  298. data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
  299. data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
  300. data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
  301. data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
  302. data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
  303. data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
  304. data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
  305. data/spec/mongoid/relations/cascading_spec.rb +0 -355
  306. data/spec/mongoid/relations/constraint_spec.rb +0 -75
  307. data/spec/mongoid/relations/conversions_spec.rb +0 -128
  308. data/spec/mongoid/relations/metadata_spec.rb +0 -1985
  309. data/spec/mongoid/relations/options_spec.rb +0 -35
  310. data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
  311. data/spec/support/cluster_config.rb +0 -158
  312. data/spec/support/constraints.rb +0 -101
  313. data/spec/support/macros.rb +0 -20
  314. data/spec/support/session_registry.rb +0 -50
  315. data/spec/support/spec_config.rb +0 -42
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ module Mongoid
3
+ module Association
4
+ module Touchable
5
+
6
+ module InstanceMethods
7
+
8
+ # Touch the document, in effect updating its updated_at timestamp and
9
+ # optionally the provided field to the current time. If any belongs_to
10
+ # relations exist with a touch option, they will be updated as well.
11
+ #
12
+ # @example Update the updated_at timestamp.
13
+ # document.touch
14
+ #
15
+ # @example Update the updated_at and provided timestamps.
16
+ # document.touch(:audited)
17
+ #
18
+ # @note This will not autobuild relations if those options are set.
19
+ #
20
+ # @param [ Symbol ] field The name of an additional field to update.
21
+ #
22
+ # @return [ true/false ] false if record is new_record otherwise true.
23
+ #
24
+ # @since 3.0.0
25
+ def touch(field = nil)
26
+ return false if _root.new_record?
27
+ current = Time.now
28
+ field = database_field_name(field)
29
+ write_attribute(:updated_at, current) if respond_to?("updated_at=")
30
+ write_attribute(field, current) if field
31
+
32
+ touches = touch_atomic_updates(field)
33
+ unless touches["$set"].blank?
34
+ selector = atomic_selector
35
+ _root.collection.find(selector).update_one(positionally(selector, touches))
36
+ end
37
+ run_callbacks(:touch)
38
+ true
39
+ end
40
+ end
41
+
42
+ extend self
43
+
44
+ # Add the association to the touchable relations if the touch option was
45
+ # provided.
46
+ #
47
+ # @example Add the touchable.
48
+ # Model.define_touchable!(assoc)
49
+ #
50
+ # @param [ Association ] association The association metadata.
51
+ #
52
+ # @return [ Class ] The model class.
53
+ #
54
+ # @since 3.0.0
55
+ def define_touchable!(association)
56
+ name = association.name
57
+ method_name = define_relation_touch_method(name, association)
58
+ association.inverse_class.tap do |klass|
59
+ klass.after_save method_name
60
+ klass.after_destroy method_name
61
+ klass.after_touch method_name
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ # Define the method that will get called for touching belongs_to
68
+ # relations.
69
+ #
70
+ # @api private
71
+ #
72
+ # @example Define the touch relation.
73
+ # Model.define_relation_touch_method(:band)
74
+ # Model.define_relation_touch_method(:band, :band_updated_at)
75
+ #
76
+ # @param [ Symbol ] name The name of the relation.
77
+ # @param [ Association ] association The association metadata.
78
+ #
79
+ # @since 3.1.0
80
+ #
81
+ # @return [ Symbol ] The method name.
82
+ def define_relation_touch_method(name, association)
83
+ association.relation_class.send(:include, InstanceMethods)
84
+ method_name = "touch_#{name}_after_create_or_destroy"
85
+ association.inverse_class.class_eval <<-TOUCH, __FILE__, __LINE__ + 1
86
+ def #{method_name}
87
+ without_autobuild do
88
+ relation = __send__(:#{name})
89
+ relation.touch #{":#{association.touch_field}" if association.touch_field} if relation
90
+ end
91
+ end
92
+ TOUCH
93
+ method_name.to_sym
94
+ end
95
+ end
96
+ end
97
+ end
@@ -36,7 +36,7 @@ module Mongoid
36
36
  # @since 2.2.0
37
37
  def add_atomic_pull(document)
38
38
  document.flagged_for_destroy = true
39
- (delayed_atomic_pulls[document.metadata_name.to_s] ||= []).push(document)
39
+ (delayed_atomic_pulls[document.association_name.to_s] ||= []).push(document)
40
40
  end
41
41
 
42
42
  # Add an atomic unset for the document.
@@ -51,7 +51,7 @@ module Mongoid
51
51
  # @since 3.0.0
52
52
  def add_atomic_unset(document)
53
53
  document.flagged_for_destroy = true
54
- (delayed_atomic_unsets[document.metadata_name.to_s] ||= []).push(document)
54
+ (delayed_atomic_unsets[document.association_name.to_s] ||= []).push(document)
55
55
  end
56
56
 
57
57
  # Returns path of the attribute for modification
@@ -110,10 +110,10 @@ module Mongoid
110
110
  # performed in a single operation. Conflicting modifications are
111
111
  # detected by the 'haveConflictingMod' function in MongoDB.
112
112
  # Examination of the code suggests that two modifications (a $set
113
- # and a $push with $each, for example) conflict if:
113
+ # and a $pushAll, for example) conflict if:
114
114
  # (1) the key paths being modified are equal.
115
115
  # (2) one key path is a prefix of the other.
116
- # So a $set of 'addresses.0.street' will conflict with a $push and $each
116
+ # So a $set of 'addresses.0.street' will conflict with a $pushAll
117
117
  # to 'addresses', and we will need to split our update into two
118
118
  # pieces. We do not, however, attempt to match MongoDB's logic
119
119
  # exactly. Instead, we assume that two updates conflict if the
@@ -189,7 +189,7 @@ module Mongoid
189
189
  #
190
190
  # @since 2.1.0
191
191
  def atomic_paths
192
- @atomic_paths ||= __metadata ? __metadata.path(self) : Atomic::Paths::Root.new(self)
192
+ @atomic_paths ||= _association ? _association.path(self) : Atomic::Paths::Root.new(self)
193
193
  end
194
194
 
195
195
  # Get all the attributes that need to be pulled.
@@ -218,7 +218,7 @@ module Mongoid
218
218
  # @example Get the pushes.
219
219
  # person.atomic_pushes
220
220
  #
221
- # @return [ Hash ] The The $push and $each operations.
221
+ # @return [ Hash ] The $pushAll operations.
222
222
  #
223
223
  # @since 2.1.0
224
224
  def atomic_pushes
@@ -68,7 +68,7 @@ module Mongoid
68
68
  modifications.each_pair do |field, value|
69
69
  push_fields[field] = field
70
70
  mods = push_conflict?(field) ? conflicting_pushes : pushes
71
- add_operation(mods, field, { '$each' => Array.wrap(value) })
71
+ add_operation(mods, field, Array.wrap(value))
72
72
  end
73
73
  end
74
74
 
@@ -118,12 +118,8 @@ module Mongoid
118
118
  # @since 2.2.0
119
119
  def add_operation(mods, field, value)
120
120
  if mods.has_key?(field)
121
- if mods[field].is_a?(Array)
122
- value.each do |val|
123
- mods[field].push(val)
124
- end
125
- elsif mods[field]['$each']
126
- mods[field]['$each'].concat(value['$each'])
121
+ value.each do |val|
122
+ mods[field].push(val)
127
123
  end
128
124
  else
129
125
  mods[field] = value
@@ -194,7 +190,7 @@ module Mongoid
194
190
  #
195
191
  # @since 2.2.0
196
192
  def conflicting_pushes
197
- conflicts["$push"] ||= {}
193
+ conflicts["$pushAll"] ||= {}
198
194
  end
199
195
 
200
196
  # Get the conflicting set modifications.
@@ -281,16 +277,16 @@ module Mongoid
281
277
  self["$pull"] ||= {}
282
278
  end
283
279
 
284
- # Get the $push/$each operations or initialize a new one.
280
+ # Get the $pushAll operations or intialize a new one.
285
281
  #
286
- # @example Get the $push/$each operations.
282
+ # @example Get the $pushAll operations.
287
283
  # modifiers.pushes
288
284
  #
289
- # @return [ Hash ] The $push/$each operations.
285
+ # @return [ Hash ] The $pushAll operations.
290
286
  #
291
287
  # @since 2.1.0
292
288
  def pushes
293
- self["$push"] ||= {}
289
+ self["$pushAll"] ||= {}
294
290
  end
295
291
 
296
292
  # Get the $set operations or intialize a new one.
@@ -35,7 +35,7 @@ module Mongoid
35
35
  def position
36
36
  pos = parent.atomic_position
37
37
  locator = document.new_record? ? "" : ".#{document._index}"
38
- "#{pos}#{"." unless pos.blank?}#{document.__metadata.store_as}#{locator}"
38
+ "#{pos}#{"." unless pos.blank?}#{document._association.store_as}#{locator}"
39
39
  end
40
40
  end
41
41
  end
@@ -34,7 +34,7 @@ module Mongoid
34
34
  # @since 2.1.0
35
35
  def position
36
36
  pos = parent.atomic_position
37
- "#{pos}#{"." unless pos.blank?}#{document.__metadata.store_as}"
37
+ "#{pos}#{"." unless pos.blank?}#{document._association.store_as}"
38
38
  end
39
39
  end
40
40
  end
@@ -163,7 +163,8 @@ module Mongoid
163
163
  #
164
164
  # @since 1.0.0
165
165
  def write_attribute(name, value)
166
- as_writable_attribute!(name) do |access|
166
+ access = database_field_name(name)
167
+ if attribute_writable?(access)
167
168
  _assigning do
168
169
  validate_attribute_value(access, value)
169
170
  localized = fields[access].try(:localized?)
@@ -48,15 +48,15 @@ module Mongoid
48
48
  args.each do |name|
49
49
  meth = "#{name}_attributes="
50
50
  self.nested_attributes["#{name}_attributes"] = meth
51
- metadata = relations[name.to_s]
52
- raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless metadata
53
- autosave_nested_attributes(metadata)
51
+ association = relations[name.to_s]
52
+ raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless association
53
+ autosave_nested_attributes(association)
54
54
  re_define_method(meth) do |attrs|
55
55
  _assigning do
56
- if metadata.polymorphic? and metadata.inverse_type
57
- options = options.merge!(:class_name => self.send(metadata.inverse_type))
56
+ if association.polymorphic? and association.inverse_type
57
+ options = options.merge!(:class_name => self.send(association.inverse_type))
58
58
  end
59
- metadata.nested_builder(attrs, options).build(self)
59
+ association.nested_builder(attrs, options).build(self)
60
60
  end
61
61
  end
62
62
  end
@@ -71,12 +71,12 @@ module Mongoid
71
71
  # @example Add the autosave if appropriate.
72
72
  # Person.autosave_nested_attributes(metadata)
73
73
  #
74
- # @param [ Metadata ] metadata The existing relation metadata.
74
+ # @param [ Association ] association The existing association metadata.
75
75
  #
76
76
  # @since 3.1.4
77
- def autosave_nested_attributes(metadata)
78
- unless metadata.autosave == false
79
- autosave(metadata.merge!(autosave: true))
77
+ def autosave_nested_attributes(association)
78
+ if association.autosave?
79
+ Association::Referenced::AutoSave.define_autosave!(association)
80
80
  end
81
81
  end
82
82
  end
@@ -133,9 +133,9 @@ module Mongoid
133
133
  # @since 2.0.0.rc.7
134
134
  def process_relations
135
135
  pending_relations.each_pair do |name, value|
136
- metadata = relations[name]
136
+ association = relations[name]
137
137
  if value.is_a?(Hash)
138
- metadata.nested_builder(value, {}).build(self)
138
+ association.nested_builder(value, {}).build(self)
139
139
  else
140
140
  send("#{name}=", value)
141
141
  end
@@ -22,17 +22,15 @@ module Mongoid
22
22
  # readonly.
23
23
  #
24
24
  # @since 3.0.0
25
- #
26
- # @deprecated Use #as_writable_attribute! instead.
27
25
  def attribute_writable?(name)
28
- new_record? || !readonly_attributes.include?(database_field_name(name))
26
+ new_record? || (!readonly_attributes.include?(name) && _loaded?(name))
29
27
  end
30
28
 
31
29
  private
32
30
 
33
31
  def as_writable_attribute!(name, value = :nil)
34
32
  normalized_name = database_field_name(name)
35
- if new_record? || (!readonly_attributes.include?(normalized_name) && _loaded?(normalized_name))
33
+ if attribute_writable?(normalized_name)
36
34
  yield(normalized_name)
37
35
  else
38
36
  raise Errors::ReadonlyAttribute.new(name, value)
@@ -3,14 +3,12 @@ require "mongoid/clients/factory"
3
3
  require "mongoid/clients/validators"
4
4
  require "mongoid/clients/storage_options"
5
5
  require "mongoid/clients/options"
6
- require "mongoid/clients/sessions"
7
6
 
8
7
  module Mongoid
9
8
  module Clients
10
9
  extend ActiveSupport::Concern
11
10
  include StorageOptions
12
11
  include Options
13
- include Sessions
14
12
 
15
13
  class << self
16
14
 
@@ -38,7 +38,7 @@ module Mongoid
38
38
  def mongo_client
39
39
  persistence_context.client
40
40
  end
41
-
41
+
42
42
  def persistence_context
43
43
  PersistenceContext.get(self) ||
44
44
  PersistenceContext.get(self.class) ||
@@ -61,7 +61,6 @@ module Mongoid
61
61
  # @since 4.0.0
62
62
  def reset_storage_options!
63
63
  self.storage_options = storage_options_defaults.dup
64
- PersistenceContext.clear(self)
65
64
  end
66
65
 
67
66
  # Get the default storage options.
@@ -43,7 +43,7 @@ module Mongoid
43
43
  include Inspectable
44
44
  include Matchable
45
45
  include Persistable
46
- include Relations
46
+ include Association
47
47
  include Reloadable
48
48
  include Scopable
49
49
  include Selectable
@@ -70,7 +70,7 @@ module Mongoid
70
70
  Interceptable,
71
71
  Matchable,
72
72
  Persistable,
73
- Relations,
73
+ Association,
74
74
  Reloadable,
75
75
  Scopable,
76
76
  Serializable,
@@ -83,8 +83,7 @@ module Mongoid
83
83
  Traversable,
84
84
  Validatable,
85
85
  Equality,
86
- Relations::Synchronization,
87
- Relations::Macros,
86
+ Association::Referenced::Syncable,
88
87
  ActiveModel::Model,
89
88
  ActiveModel::Validations
90
89
  ]
@@ -27,6 +27,7 @@ module Mongoid
27
27
  option :log_level, default: :info
28
28
  option :belongs_to_required_by_default, default: true
29
29
  option :app_name, default: nil
30
+ option :background_indexing, default: false
30
31
 
31
32
  # Has Mongoid been configured? This is checking that at least a valid
32
33
  # client config exists.
@@ -23,7 +23,7 @@ module Mongoid
23
23
  #
24
24
  # @since 3.0.0
25
25
  def aggregates(field)
26
- result = collection.find.aggregate(pipeline(field), session: _session).to_a
26
+ result = collection.find.aggregate(pipeline(field)).to_a
27
27
  if result.empty?
28
28
  { "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
29
29
  else
@@ -106,10 +106,10 @@ module Mongoid
106
106
  view.update_many("$push" => collect_operations(pushes))
107
107
  end
108
108
 
109
- # Perform an atomic $push/$each operation on the matching documents.
109
+ # Perform an atomic $pushAll operation on the matching documents.
110
110
  #
111
111
  # @example Push the values to the matching docs.
112
- # context.push_all(members: [ "Alan", "Fletch" ])
112
+ # context.push(members: [ "Alan", "Fletch" ])
113
113
  #
114
114
  # @param [ Hash ] pushes The operations.
115
115
  #
@@ -117,10 +117,7 @@ module Mongoid
117
117
  #
118
118
  # @since 3.0.0
119
119
  def push_all(pushes)
120
- push_each_updates = collect_operations(pushes).each.inject({}) do |ops, (field, elements)|
121
- ops.merge!(field => {'$each' => elements})
122
- end
123
- view.update_many("$push" => push_each_updates)
120
+ view.update_many("$pushAll" => collect_operations(pushes))
124
121
  end
125
122
 
126
123
  # Perform an atomic $rename of fields on the matching documents.
@@ -165,13 +165,13 @@ module Mongoid
165
165
  def raw
166
166
  validate_out!
167
167
  cmd = command
168
- opts = { read: cmd.delete(:read) } if cmd[:read]
169
- @map_reduce.database.command(cmd, (opts || {}).merge(session: _session)).first
168
+ opts = { read: cmd.delete(:read).options } if cmd[:read]
169
+ @map_reduce.database.command(cmd, opts || {}).first
170
170
  end
171
171
  alias :results :raw
172
172
 
173
173
  # Execute the map/reduce, returning the raw output.
174
- # Useful when you don't care about map/reduce's output.
174
+ # Useful when you don't care about map/reduce's ouptut.
175
175
  #
176
176
  # @example Run the map reduce
177
177
  # map_reduce.execute
@@ -249,10 +249,6 @@ module Mongoid
249
249
  def validate_out!
250
250
  raise Errors::NoMapReduceOutput.new({}) unless @map_reduce.out
251
251
  end
252
-
253
- def _session
254
- criteria.send(:_session)
255
- end
256
252
  end
257
253
  end
258
254
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
2
  require "mongoid/contextual/aggregable/memory"
3
- require "mongoid/relations/eager"
3
+ require "mongoid/association/eager_loadable"
4
4
 
5
5
  module Mongoid
6
6
  module Contextual
7
7
  class Memory
8
8
  include Enumerable
9
9
  include Aggregable::Memory
10
- include Relations::Eager
10
+ include Association::EagerLoadable
11
11
  include Queryable
12
12
  include Positional
13
13
 
@@ -48,8 +48,7 @@ module Mongoid
48
48
  end
49
49
  unless removed.empty?
50
50
  collection.find(selector).update_one(
51
- positionally(selector, "$pullAll" => { path => removed }),
52
- session: _session
51
+ positionally(selector, "$pullAll" => { path => removed })
53
52
  )
54
53
  end
55
54
  deleted
@@ -130,7 +129,7 @@ module Mongoid
130
129
  # @return [ Document ] The first document.
131
130
  #
132
131
  # @since 3.0.0
133
- def first
132
+ def first(*args)
134
133
  eager_load([documents.first]).first
135
134
  end
136
135
  alias :one :first
@@ -304,7 +303,7 @@ module Mongoid
304
303
  updates["$set"].merge!(doc.atomic_updates["$set"] || {})
305
304
  doc.move_changes
306
305
  end
307
- collection.find(selector).update_one(updates, session: _session) unless updates["$set"].empty?
306
+ collection.find(selector).update_one(updates) unless updates["$set"].empty?
308
307
  end
309
308
 
310
309
  # Get the limiting value.
@@ -445,10 +444,6 @@ module Mongoid
445
444
  doc._parent.remove_child(doc)
446
445
  doc.destroyed = true
447
446
  end
448
-
449
- def _session
450
- @criteria.send(:_session)
451
- end
452
447
  end
453
448
  end
454
449
  end