mongoid 2.4.0 → 2.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. data/CHANGELOG.md +329 -1
  2. data/Rakefile +0 -9
  3. data/lib/config/locales/bg.yml +1 -0
  4. data/lib/config/locales/de.yml +1 -0
  5. data/lib/config/locales/en-GB.yml +1 -0
  6. data/lib/config/locales/en.yml +1 -0
  7. data/lib/config/locales/es.yml +1 -0
  8. data/lib/config/locales/fr.yml +1 -0
  9. data/lib/config/locales/hi.yml +1 -0
  10. data/lib/config/locales/hu.yml +1 -0
  11. data/lib/config/locales/id.yml +1 -0
  12. data/lib/config/locales/it.yml +1 -0
  13. data/lib/config/locales/ja.yml +1 -0
  14. data/lib/config/locales/kr.yml +1 -0
  15. data/lib/config/locales/nl.yml +1 -0
  16. data/lib/config/locales/pl.yml +1 -0
  17. data/lib/config/locales/pt-BR.yml +1 -0
  18. data/lib/config/locales/pt.yml +1 -0
  19. data/lib/config/locales/ro.yml +1 -0
  20. data/lib/config/locales/ru.yml +1 -0
  21. data/lib/config/locales/sv.yml +1 -0
  22. data/lib/config/locales/vi.yml +1 -0
  23. data/lib/config/locales/zh-CN.yml +1 -0
  24. data/lib/mongoid/atomic/modifiers.rb +56 -15
  25. data/lib/mongoid/atomic.rb +14 -8
  26. data/lib/mongoid/attributes.rb +1 -1
  27. data/lib/mongoid/callbacks.rb +3 -3
  28. data/lib/mongoid/collection.rb +5 -1
  29. data/lib/mongoid/collections/retry.rb +2 -1
  30. data/lib/mongoid/components.rb +2 -1
  31. data/lib/mongoid/config/database.rb +4 -7
  32. data/lib/mongoid/config/environment.rb +4 -2
  33. data/lib/mongoid/config/replset_database.rb +3 -5
  34. data/lib/mongoid/config.rb +18 -0
  35. data/lib/mongoid/contexts/enumerable.rb +26 -1
  36. data/lib/mongoid/contexts/mongo.rb +62 -14
  37. data/lib/mongoid/copyable.rb +38 -8
  38. data/lib/mongoid/criteria.rb +1 -0
  39. data/lib/mongoid/criterion/exclusion.rb +3 -1
  40. data/lib/mongoid/criterion/inclusion.rb +2 -2
  41. data/lib/mongoid/criterion/optional.rb +2 -2
  42. data/lib/mongoid/criterion/selector.rb +25 -4
  43. data/lib/mongoid/cursor.rb +4 -2
  44. data/lib/mongoid/dirty.rb +61 -18
  45. data/lib/mongoid/document.rb +6 -2
  46. data/lib/mongoid/extensions/hash/criteria_helpers.rb +3 -1
  47. data/lib/mongoid/extensions/string/inflections.rb +1 -1
  48. data/lib/mongoid/factory.rb +3 -3
  49. data/lib/mongoid/fields/internal/array.rb +4 -9
  50. data/lib/mongoid/fields/internal/big_decimal.rb +7 -1
  51. data/lib/mongoid/fields/internal/date_time.rb +1 -1
  52. data/lib/mongoid/fields/internal/false_class.rb +10 -0
  53. data/lib/mongoid/fields/internal/foreign_keys/array.rb +22 -8
  54. data/lib/mongoid/fields/internal/set.rb +1 -1
  55. data/lib/mongoid/fields/internal/timekeeping.rb +2 -1
  56. data/lib/mongoid/fields/internal/true_class.rb +10 -0
  57. data/lib/mongoid/fields/mappings.rb +14 -13
  58. data/lib/mongoid/fields/serializable.rb +41 -3
  59. data/lib/mongoid/fields.rb +154 -26
  60. data/lib/mongoid/hierarchy.rb +6 -1
  61. data/lib/mongoid/identity_map.rb +15 -0
  62. data/lib/mongoid/logger.rb +7 -1
  63. data/lib/mongoid/matchers/all.rb +8 -1
  64. data/lib/mongoid/matchers/in.rb +8 -1
  65. data/lib/mongoid/matchers/strategies.rb +6 -2
  66. data/lib/mongoid/multi_database.rb +5 -0
  67. data/lib/mongoid/named_scope.rb +17 -1
  68. data/lib/mongoid/nested_attributes.rb +1 -1
  69. data/lib/mongoid/observer.rb +7 -0
  70. data/lib/mongoid/persistence/insertion.rb +2 -1
  71. data/lib/mongoid/persistence/operations/update.rb +0 -9
  72. data/lib/mongoid/persistence.rb +5 -5
  73. data/lib/mongoid/railtie.rb +22 -4
  74. data/lib/mongoid/relations/bindings/referenced/in.rb +31 -11
  75. data/lib/mongoid/relations/bindings/referenced/many.rb +8 -8
  76. data/lib/mongoid/relations/bindings/referenced/one.rb +8 -8
  77. data/lib/mongoid/relations/builders/nested_attributes/many.rb +3 -1
  78. data/lib/mongoid/relations/cascading/delete.rb +29 -2
  79. data/lib/mongoid/relations/cascading/destroy.rb +18 -1
  80. data/lib/mongoid/relations/cascading/nullify.rb +18 -1
  81. data/lib/mongoid/relations/cascading.rb +0 -1
  82. data/lib/mongoid/relations/embedded/atomic.rb +3 -3
  83. data/lib/mongoid/relations/embedded/many.rb +58 -26
  84. data/lib/mongoid/relations/embedded/one.rb +1 -1
  85. data/lib/mongoid/relations/metadata.rb +33 -1
  86. data/lib/mongoid/relations/one.rb +12 -0
  87. data/lib/mongoid/relations/proxy.rb +6 -3
  88. data/lib/mongoid/relations/referenced/many.rb +14 -9
  89. data/lib/mongoid/relations/referenced/many_to_many.rb +3 -4
  90. data/lib/mongoid/relations/targets/enumerable.rb +9 -3
  91. data/lib/mongoid/relations.rb +3 -1
  92. data/lib/mongoid/serialization.rb +18 -6
  93. data/lib/mongoid/state.rb +1 -1
  94. data/lib/mongoid/threaded.rb +26 -0
  95. data/lib/mongoid/timestamps/updated.rb +1 -1
  96. data/lib/mongoid/validations/format.rb +20 -0
  97. data/lib/mongoid/validations/length.rb +20 -0
  98. data/lib/mongoid/validations/localizable.rb +30 -0
  99. data/lib/mongoid/validations/presence.rb +6 -2
  100. data/lib/mongoid/validations/uniqueness.rb +162 -30
  101. data/lib/mongoid/validations.rb +54 -2
  102. data/lib/mongoid/version.rb +1 -1
  103. data/lib/mongoid/versioning.rb +12 -3
  104. data/lib/mongoid.rb +1 -0
  105. data/lib/rails/mongoid.rb +18 -12
  106. metadata +58 -41
  107. data/lib/mongoid/relations/cascading/strategy.rb +0 -26
data/CHANGELOG.md CHANGED
@@ -3,7 +3,335 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/docs/upgrading.html).
5
5
 
6
- ## 2.4.0 \[ In Development \] \[ Branch: master \]
6
+ ## 2.4.12
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#2178 Ensure destroy callbacks are run post replacement of an embeds one
11
+ relation.
12
+
13
+ * \#2169 Allow saves to pass when documents are destroyed after the save
14
+ in a callback.
15
+
16
+ * \#2144 Uniqueness validation on paranoid documents now properly scopes.
17
+
18
+ * \#2127 Don't unbind parents of embedded documents mid nested
19
+ attributes deletion.
20
+
21
+ ## 2.4.11
22
+
23
+ ### Resolved Issues
24
+
25
+ * This release forces a cap on the mongo driver version at 1.6.2 due to
26
+ changes in the `Mongo::Connection.from_uri` API not allowing valid
27
+ connection options anymore.
28
+
29
+ * \#2040 Fixed bad interpolation for locale presence validation.
30
+
31
+ * \#2038 Allow inverse relations to be determined by foreign keys alone
32
+ if defined on both sides, not just an inverse_of declaration.
33
+
34
+ * \#2023 Allow serilialization of dynamic types that conflict with core
35
+ Ruby methods to still be serialized.
36
+
37
+ * \#2008 Presence validation should hit the db to check validity if the
38
+ relation in memory is blank.
39
+
40
+ * \#2006 Allow excluding only the _id field post execution of an #only call.
41
+
42
+ ## 2.4.10
43
+
44
+ ### Resolved Issues
45
+
46
+ * \#2003 Don't fail on document generation when an embedded document was
47
+ stored as nil in the database.
48
+
49
+ * \#1997 Don't delete paranoid embedded docs via nested attributes when
50
+ a before_destroy callback returns false.
51
+
52
+ * \#1994 `dependent: :delete` only hits the database once now for one to
53
+ many and many to many relations instead of once for each document.
54
+
55
+ * \#1987 Don't double-insert documents into identity map when eager loading
56
+ twice inside the unit of work.
57
+
58
+ * \#1976 Don't execute eager load queries when base query is empty.
59
+
60
+ * \#1953 Uniqueness validation now works on localized fields.
61
+
62
+ * \#1936 Allow setting n levels deep embedded documents atomically without
63
+ conflicting mods when not using nested attributes or documents themselves
64
+ in an update call from the parent.
65
+
66
+ * \#1957/\#1954 Ensure database name is set with inheritance.
67
+ (Hans Hasselberg)
68
+
69
+ ## 2.4.9
70
+
71
+ ### Resolved Issues
72
+
73
+ * \#1943 Ensure numericality validation works for big decimals.
74
+
75
+ * \#1938 Length validation now works with localized fields.
76
+
77
+ * \#1936 Conflicting pushes with other pushes is now properly handled.
78
+
79
+ * \#1933 `Proxy#extend` should delegate through to the target, where
80
+ extending the proxy itself is now handled through `Proxy#proxy_extend`.
81
+
82
+ * \#1930 Ensure complex criteria are expanded in all where clauses.
83
+ (Hans Hasselberg)
84
+
85
+ * \#1928 Deletion of embedded documents via nested attributes now performs
86
+ a $pull with id match criteria instead of a $pullAll to cover all cases.
87
+ Previously newly added defaults to documents that had already persisted
88
+ could not be deleted in this matter since the doc did not match what was
89
+ in the database.
90
+
91
+ * \#1924/\#1917 Fix pushing to embedded relations with default scopes not
92
+ scoping on the new document. (Hans Hasselberg)
93
+
94
+ * \#1922/\#1919 Dropping collections unmemoizes the internally wrapped
95
+ collection, in order to ensure when defining capped collections that
96
+ they are always recreated as capped. (Hans Hasselberg)
97
+
98
+ * \#1916/\#1913 Uniqueness validation no longer is affected by the default
99
+ scope. (Hans Hasselberg)
100
+
101
+ * \#1778 Ensure foreign keys are always set regardless of binding state.
102
+
103
+ ## 2.4.8
104
+
105
+ ### Resolved Issues
106
+
107
+ * \#1892 When getting not master operation error, Mongoid should reconnect
108
+ before retrying the operation.
109
+
110
+ * \#1887 Don't cascade callbacks to children that don't have the callback
111
+ defined.
112
+
113
+ * \#1882 Don't expand duplicate id criterion into an $and with duplicate
114
+ selections.
115
+
116
+ * \#1878 Fixed default application values not to apply in certain `only`
117
+ or `without` selection on iteration, not just `first` and `last`.
118
+
119
+ * \#1874 Fixed the reject all blank proc constant to handle values
120
+ properly with a destroy non blank value. (Stefan Daschek)
121
+
122
+ * \#1869/\#1868 Delayed atomic sets now uses the atomic path instead of
123
+ the metadata name to fix multiple level embedding issues.
124
+ (Chris Micacchi provided specs)
125
+
126
+ * \#1866 Post processed defaults (procs) should be applied post binding
127
+ of the child in a relation.build.
128
+
129
+ ## 2.4.7
130
+
131
+ ### Resolved Issues
132
+
133
+ * Ensure reloading of embedded documents retains reference to the parent.
134
+
135
+ * \#1837 Always pass symbol options to the driver.
136
+
137
+ * \#1836 Ensure relation counts pick up persisted document that have not
138
+ had the foreign key link persisted.
139
+
140
+ * \#1820 Destroying embedded documents in an embeds_many should also
141
+ removed the document from the underlying _uncoped target and reindex
142
+ the relation.
143
+
144
+ * \#1814 Don't cascade callbacks on after_initialize.
145
+
146
+ * \#1800 Invalid options for the Mongo connection are now filtered out.
147
+
148
+ * \#1785 Case equality has been fixed to handle instance checks properly.
149
+
150
+ ## 2.4.6
151
+
152
+ ### Resolved Issues
153
+
154
+ * \#1772 Allow skip and limit to convert strings to integers. (Jean Boussier)
155
+
156
+ * \#1767 Model#update_attributes accepts mass assignment options again.
157
+ (Hans Hasselberg)
158
+
159
+ * \#1762 Criteria#any_of now properly handles localized fields.
160
+
161
+ * \#1758 Metadata now returns self on options for external library support.
162
+
163
+ * \#1757 Ensure serialization converts any attribute types to the type
164
+ defined by the field.
165
+
166
+ * \#1756 Serializable hash options should pass through to embedded docs.
167
+
168
+ ## 2.4.5
169
+
170
+ ### Resolved Issues
171
+
172
+ * \#1751 Mongoid's logger now responds to level for Ruby logging API
173
+ compatibility.
174
+
175
+ * \#1744/#1750 Sorting works now for localized fields in embedded documents
176
+ using the criteria API. (Hans Hasselberg)
177
+
178
+ * \#1746 Presence validation now shows which locales were empty for
179
+ localized fields. (Cyril Mougel)
180
+
181
+ * \#1727 Allow dot notation in embedded criteria to work on both embeds one
182
+ and embeds many. (Lyle Underwood)
183
+
184
+ * \#1723 Initialize callbacks should cascade through children without needing
185
+ to determine if the child is changed.
186
+
187
+ * \#1715 Serializable hashes are now consistent on inclusion of embedded
188
+ documents per or post save.
189
+
190
+ * \#1713 Fixing === checks when comparing a class with an instance of a
191
+ subclass.
192
+
193
+ * \#1495 Callbacks no longer get the 'super called outside of method` errors on
194
+ busted 1.8.7 rubies.
195
+
196
+ ## 2.4.4
197
+
198
+ ### Resolved Issues
199
+
200
+ * \#1705 Allow changing the order of many to many foreign keys.
201
+
202
+ * \#1703 Updated at is now versioned again. (Lucas Souza)
203
+
204
+ * \#1686 Set the base metadata on unbind as well as bind for belongs to
205
+ relations.
206
+
207
+ * \#1681 Attempt to create indexes for models without namespacing if the
208
+ namespace does not exist for the subdirectory.
209
+
210
+ * \#1676 Allow eager loading to work as a default scope.
211
+
212
+ * \#1665/#1672 Expand complex criteria in nested criteria selectors, like
213
+ #matches. (Hans Hasselberg)
214
+
215
+ * \#1668 Ensure Mongoid logger exists before calling warn. (Rémy Coutable)
216
+
217
+ * \#1661 Ensure uniqueness validation works on cloned documents.
218
+
219
+ * \#1659 Clear delayed atomic sets when resetting the same embedded relation.
220
+
221
+ * \#1656/#1657 Don't hit database for uniqueness validation if BOTH scope
222
+ and attribute hasn't changed. (priyaaank)
223
+
224
+ * \#1205/#1642 When limiting fields returned from the database via
225
+ `Criteria#only` and `Criteria#without` and then subsequently saving
226
+ the document. Default values no longer override excluded fields.
227
+
228
+ ## 2.4.3
229
+
230
+ ### Resolved Issues
231
+
232
+ * \#1647 DateTime serialization when already in UTC does not convert to
233
+ local time.
234
+
235
+ * \#1640 Update consumers should be tied to the name of the collection
236
+ they persist to, not the name of the class.
237
+
238
+ * \#1636 Scopes no longer modify parent class scopes when subclassing.
239
+ (Hans Hasselberg)
240
+
241
+ * \#1629 $all and $in criteria on embedded many relations now properly
242
+ handles regex searches and elements of varying length. (Douwe Maan)
243
+
244
+ * \#1623 Default scopes no longer break Mongoid::Versioning.
245
+ (Hans Hasselberg)
246
+
247
+ * \#1605 Fix regression of rescue responses, Rails 3.2
248
+
249
+ ## 2.4.2
250
+
251
+ ### Resolved Issues
252
+
253
+ * \#1627 Validating format now works properly with localized fields.
254
+ (Douwe Maan)
255
+
256
+ * \#1617 Relation proxy methods now show up in Mongoid's list of
257
+ prohibited fields.
258
+
259
+ * \#1615 Allow a single configuration of host and port for all spec runs,
260
+ overridden by setting MONGOID_SPEC_HOST and MONGOID_SPEC_PORT env vars.
261
+
262
+ * \#1610 When versioning paranoid documents and max version is set, hard
263
+ delete old versions from the embedded relation.
264
+
265
+ * \#1609 Allow connection retry during cursor iteration as well as all other
266
+ operations.
267
+
268
+ * \#1608 Guard against no method errors when passing ids in nested attributes
269
+ and the documents do not exist.
270
+
271
+ * \#1605 Remove deprecation warning on rescue responses, Rails 3.2
272
+
273
+ * \#1602 Preserve structure of $and and $or queries when typecasting.
274
+
275
+ * \#1600 Uniqueness validation no longer errors when provided a relation.
276
+
277
+ * \#1599 Make sure enumerable targets yield to what is in memory first when
278
+ performing #each, not always the unloaded first.
279
+
280
+ * \#1597 Fix the ability to change the order of array fields with the same
281
+ elements.
282
+
283
+ * \#1590 Allow proper serialization of boolean values in criteria where the
284
+ field is nested inside an array.
285
+
286
+ ## 2.4.1
287
+
288
+ ### Resolved Issues
289
+
290
+ * \#1593 Arrays on embedded documents now properly atomically update when
291
+ modified from original version.
292
+
293
+ * \#1592 Don't swallow exceptions from index generation in the create_indexes
294
+ rake task.
295
+
296
+ * \#1589 Allow assignment of empty array to HABTM when no documents are yet
297
+ loaded into memory.
298
+
299
+ * \#1587 When a previous value for an array field was an explicit nil, it can
300
+ now be reset atomically with new values.
301
+
302
+ * \#1585 `Model#respond_to?` returns true now for the setter when allowing
303
+ dynamic fields.
304
+
305
+ * \#1582 Allow nil values to be set in arrays.
306
+
307
+ * \#1580 Allow arrays to be set to nil post save, and not just empty.
308
+
309
+ * \#1579 Don't call #to_a on individual set field elements in criterion.
310
+
311
+ * \#1576 Don't hit database on uniqueness validation if the field getting
312
+ validated has not changed.
313
+
314
+ * \#1571 Aliased fields get all the dirty attribute methods and all getters and
315
+ setters for both the original name and the alias. (Hans Hasselberg)
316
+
317
+ * \#1568 Fallback to development environment with warning when no env configured.
318
+
319
+ * \#1565 For fields and foreign keys with non-standard Ruby or database names,
320
+ use define_method instead of class_eval for creating the accessors and
321
+ dirty methods.
322
+
323
+ * \#1557 Internal strategy class no longer conflicts with models.
324
+
325
+ * \#1551 Parent documents now return `true` for `Model#changed?` if only child
326
+ (embedded) documents have changed.
327
+
328
+ * \#1547 Resetting persisted children from a parent save when new waits until post
329
+ callbacks, mirroring update functionality.
330
+
331
+ * \#1536 Eager loading now happens when calling `first` or `last` on a
332
+ criteria if inclusions are specified.
333
+
334
+ ## 2.4.0
7
335
 
8
336
  ### New Features
9
337
 
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "bundler"
2
2
  Bundler.setup
3
3
 
4
4
  require "rake"
5
- require "rdoc/task"
6
5
  require "rspec"
7
6
  require "rspec/core/rake_task"
8
7
 
@@ -37,13 +36,5 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
37
36
  spec.pattern = "spec/**/*_spec.rb"
38
37
  end
39
38
 
40
- RDoc::Task.new do |rdoc|
41
- rdoc.rdoc_dir = "rdoc"
42
- rdoc.title = "mongoid #{Mongoid::VERSION}"
43
- rdoc.rdoc_files.include("README*")
44
- rdoc.rdoc_files.include("CHANGELOG*")
45
- rdoc.rdoc_files.include("lib/**/*.rb")
46
- end
47
-
48
39
  task :spec => [ "spec:functional", "spec:unit" ]
49
40
  task :default => :spec
@@ -58,3 +58,4 @@ bg:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,3 +58,4 @@ de:
58
58
  scope_overwrite:
59
59
  "Scope :%{scope_name} kann nicht erzeugt werden, da bereits eine Methode
60
60
  %{model_name}.%{scope_name} existiert."
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -61,3 +61,4 @@ en-GB:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{location}"
@@ -61,3 +61,4 @@ en:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,3 +56,4 @@ es:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,3 +59,4 @@ fr:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -50,3 +50,4 @@ en:
50
50
  scope_overwrite:
51
51
  "Cannot create scope :%{scope_name}, because of existing method
52
52
  %{model_name}.%{scope_name}."
53
+ blank_on_locale: "can't be blank in %{location}"
@@ -61,3 +61,4 @@ hu:
61
61
  scope_overwrite:
62
62
  "Cannot create scope :%{scope_name}, because of existing method
63
63
  %{model_name}.%{scope_name}."
64
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,3 +59,4 @@ id:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,3 +56,4 @@ it:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{location}"
@@ -54,3 +54,4 @@ ja:
54
54
  scope_overwrite:
55
55
  "Cannot create scope :%{scope_name}, because of existing method
56
56
  %{model_name}.%{scope_name}."
57
+ blank_on_locale: "can't be blank in %{location}"
@@ -51,3 +51,4 @@ kr:
51
51
  scope_overwrite:
52
52
  "Cannot create scope :%{scope_name}, because of existing method
53
53
  %{model_name}.%{scope_name}."
54
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,3 +58,4 @@ nl:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -56,3 +56,4 @@ pl:
56
56
  scope_overwrite:
57
57
  "Cannot create scope :%{scope_name}, because of existing method
58
58
  %{model_name}.%{scope_name}."
59
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,3 +57,4 @@ pt-BR:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,3 +57,4 @@ pt:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -63,3 +63,4 @@ ro:
63
63
  scope_overwrite:
64
64
  "Cannot create scope :%{scope_name}, because of existing method
65
65
  %{model_name}.%{scope_name}."
66
+ blank_on_locale: "can't be blank in %{location}"
@@ -58,3 +58,4 @@ ru:
58
58
  scope_overwrite:
59
59
  "Cannot create scope :%{scope_name}, because of existing method
60
60
  %{model_name}.%{scope_name}."
61
+ blank_on_locale: "can't be blank in %{location}"
@@ -57,3 +57,4 @@ sv:
57
57
  scope_overwrite:
58
58
  "Cannot create scope :%{scope_name}, because of existing method
59
59
  %{model_name}.%{scope_name}."
60
+ blank_on_locale: "can't be blank in %{location}"
@@ -59,3 +59,4 @@ vi:
59
59
  scope_overwrite:
60
60
  "Cannot create scope :%{scope_name}, because of existing method
61
61
  %{model_name}.%{scope_name}."
62
+ blank_on_locale: "can't be blank in %{location}"
@@ -50,3 +50,4 @@ zh-CN:
50
50
  scope_overwrite:
51
51
  "Cannot create scope :%{scope_name}, because of existing method
52
52
  %{model_name}.%{scope_name}."
53
+ blank_on_locale: "can't be blank in %{location}"
@@ -26,18 +26,33 @@ module Mongoid #:nodoc:
26
26
  end
27
27
  end
28
28
 
29
- # Adds pull modifiers to the modifiers hash.
29
+ # Adds pull all modifiers to the modifiers hash.
30
30
  #
31
- # @example Add pull operations.
32
- # modifiers.pull({ "addresses" => { "street" => "Bond" }})
31
+ # @example Add pull all operations.
32
+ # modifiers.pull_all({ "addresses" => { "street" => "Bond" }})
33
33
  #
34
- # @param [ Hash ] modifications The pull modifiers.
34
+ # @param [ Hash ] modifications The pull all modifiers.
35
35
  #
36
- # @since 2.2.0
36
+ # @since 3.0.0
37
+ def pull_all(modifications)
38
+ modifications.each_pair do |field, value|
39
+ add_operation(pull_alls, field, value)
40
+ pull_fields[field.split(".", 2)[0]] = field
41
+ end
42
+ end
43
+
44
+ # Adds pull all modifiers to the modifiers hash.
45
+ #
46
+ # @example Add pull all operations.
47
+ # modifiers.pull({ "addresses" => { "_id" => { "$in" => [ 1, 2, 3 ]}}})
48
+ #
49
+ # @param [ Hash ] modifications The pull all modifiers.
50
+ #
51
+ # @since 3.0.0
37
52
  def pull(modifications)
38
53
  modifications.each_pair do |field, value|
39
- add_operation(pulls, field, value)
40
- pull_fields << field.split(".", 2)[0]
54
+ pulls[field] = value
55
+ pull_fields[field.split(".", 2)[0]] = field
41
56
  end
42
57
  end
43
58
 
@@ -51,6 +66,7 @@ module Mongoid #:nodoc:
51
66
  # @since 2.1.0
52
67
  def push(modifications)
53
68
  modifications.each_pair do |field, value|
69
+ push_fields[field] = field
54
70
  mods = push_conflict?(field) ? conflicting_pushes : pushes
55
71
  add_operation(mods, field, Array.wrap(value))
56
72
  end
@@ -69,7 +85,7 @@ module Mongoid #:nodoc:
69
85
  next if field == "_id"
70
86
  mods = set_conflict?(field) ? conflicting_sets : sets
71
87
  add_operation(mods, field, value)
72
- set_fields << field.split(".", 2)[0]
88
+ set_fields[field.split(".", 2)[0]] = field
73
89
  end
74
90
  end
75
91
 
@@ -133,7 +149,7 @@ module Mongoid #:nodoc:
133
149
  #
134
150
  # @since 2.2.0
135
151
  def set_conflict?(field)
136
- pull_fields.include?(field.split(".", 2)[0])
152
+ pull_fields.has_key?(field.split(".", 2)[0])
137
153
  end
138
154
 
139
155
  # Is the operation going to be a conflict for a $push?
@@ -148,7 +164,8 @@ module Mongoid #:nodoc:
148
164
  # @since 2.2.0
149
165
  def push_conflict?(field)
150
166
  name = field.split(".", 2)[0]
151
- set_fields.include?(name) || pull_fields.include?(name)
167
+ set_fields.has_key?(name) || pull_fields.has_key?(name) ||
168
+ (push_fields.keys.count { |item| item =~ /#{name}/ } > 1)
152
169
  end
153
170
 
154
171
  # Get the conflicting pull modifications.
@@ -208,7 +225,19 @@ module Mongoid #:nodoc:
208
225
  #
209
226
  # @since 2.2.0
210
227
  def pull_fields
211
- @pull_fields ||= []
228
+ @pull_fields ||= {}
229
+ end
230
+
231
+ # Get the names of the fields that need to be pushed.
232
+ #
233
+ # @example Get the push fields.
234
+ # modifiers.push_fields
235
+ #
236
+ # @return [ Array<String> ] The push fields.
237
+ #
238
+ # @since 2.2.0
239
+ def push_fields
240
+ @push_fields ||= {}
212
241
  end
213
242
 
214
243
  # Get the names of the fields that need to be set.
@@ -220,21 +249,33 @@ module Mongoid #:nodoc:
220
249
  #
221
250
  # @since 2.2.0
222
251
  def set_fields
223
- @set_fields ||= []
252
+ @set_fields ||= {}
224
253
  end
225
254
 
226
255
  # Get the $pullAll operations or intialize a new one.
227
256
  #
228
257
  # @example Get the $pullAll operations.
229
- # modifiers.pulls
258
+ # modifiers.pull_alls
230
259
  #
231
260
  # @return [ Hash ] The $pullAll operations.
232
261
  #
233
- # @since 2.1.0
234
- def pulls
262
+ # @since 3.0.0
263
+ def pull_alls
235
264
  self["$pullAll"] ||= {}
236
265
  end
237
266
 
267
+ # Get the $pull operations or intialize a new one.
268
+ #
269
+ # @example Get the $pull operations.
270
+ # modifiers.pulls
271
+ #
272
+ # @return [ Hash ] The $pull operations.
273
+ #
274
+ # @since 3.0.0
275
+ def pulls
276
+ self["$pull"] ||= {}
277
+ end
278
+
238
279
  # Get the $pushAll operations or intialize a new one.
239
280
  #
240
281
  # @example Get the $pushAll operations.
@@ -160,15 +160,18 @@ module Mongoid #:nodoc:
160
160
  #
161
161
  # @since 2.2.0
162
162
  def atomic_pulls
163
- delayed_atomic_pulls.inject({}) do |pulls, (name, docs)|
164
- pulls.tap do |pull|
165
- docs.each do |doc|
166
- (pull[doc.atomic_path] ||= []).push(doc.as_document)
167
- doc.destroyed = true
168
- doc.flagged_for_destroy = false
169
- end
163
+ pulls = {}
164
+ delayed_atomic_pulls.each_pair do |_, docs|
165
+ path = nil
166
+ ids = docs.map do |doc|
167
+ path ||= doc.atomic_path
168
+ doc.destroyed = true
169
+ doc.flagged_for_destroy = false
170
+ doc.id
170
171
  end
172
+ pulls[path] = { "_id" => { "$in" => ids }} and path = nil
171
173
  end
174
+ pulls
172
175
  end
173
176
 
174
177
  # Get all the push attributes that need to occur.
@@ -249,6 +252,9 @@ module Mongoid #:nodoc:
249
252
  # @example Get the atomic paths.
250
253
  # document.atomic_paths
251
254
  #
255
+ # @todo: Durran: Should probably raise error for embedded docs w/o
256
+ # metadata.
257
+ #
252
258
  # @return [ Object ] The associated path.
253
259
  #
254
260
  # @since 2.1.0
@@ -273,7 +279,7 @@ module Mongoid #:nodoc:
273
279
  mods.push(doc.atomic_pushes)
274
280
  mods.push(doc.atomic_array_pushes)
275
281
  mods.add_to_set(doc.atomic_array_add_to_sets)
276
- mods.pull(doc.atomic_array_pulls)
282
+ mods.pull_all(doc.atomic_array_pulls)
277
283
  end
278
284
  end
279
285
  end
@@ -77,7 +77,7 @@ module Mongoid #:nodoc:
77
77
  def respond_to?(*args)
78
78
  (Mongoid.allow_dynamic_fields &&
79
79
  attributes &&
80
- attributes.has_key?(args.first.to_s)
80
+ attributes.has_key?(args.first.to_s.reader)
81
81
  ) || super
82
82
  end
83
83