mongoid 3.0.21 → 3.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +24 -0
- data/lib/mongoid/callbacks.rb +17 -2
- data/lib/mongoid/copyable.rb +18 -5
- data/lib/mongoid/document.rb +2 -1
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/relations/referenced/many.rb +1 -1
- data/lib/mongoid/relations/referenced/many_to_many.rb +1 -1
- data/lib/mongoid/validations.rb +1 -1
- data/lib/mongoid/validations/uniqueness.rb +15 -1
- data/lib/mongoid/version.rb +1 -1
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,30 @@
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
4
4
|
[mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
|
5
5
|
|
6
|
+
## 3.0.22
|
7
|
+
|
8
|
+
### Resolved Issues
|
9
|
+
|
10
|
+
* \#2812 Fixed criteria on many to many relations when the base document is
|
11
|
+
destroyed and the foreign key has not yet been lazy evaluated.
|
12
|
+
|
13
|
+
* \#2796 Don't cascade changes on has_many relations when assigning with
|
14
|
+
a delete.
|
15
|
+
|
16
|
+
* \#2795 Fix precision on time conversions. (Tom de Bruijn)
|
17
|
+
|
18
|
+
* \#2794 Don't autobuild when reading a relation for validation.
|
19
|
+
|
20
|
+
* \#2790 `becomes` now copies embedded documents even if they were protected
|
21
|
+
by mass assignment.
|
22
|
+
|
23
|
+
* \#2787 Allow `becomes` to replace the document in the identity map.
|
24
|
+
|
25
|
+
* \#2786 Fixed regressed cascading callbacks on destroy not firing.
|
26
|
+
|
27
|
+
* \#2784 Fixed uniqueness validation properly getting added to subclasses.
|
28
|
+
(Takeshi Akima)
|
29
|
+
|
6
30
|
## 3.0.21
|
7
31
|
|
8
32
|
### Resolved Issues
|
data/lib/mongoid/callbacks.rb
CHANGED
@@ -52,6 +52,21 @@ module Mongoid
|
|
52
52
|
respond_to?("_#{kind}_callbacks")
|
53
53
|
end
|
54
54
|
|
55
|
+
# Is the document currently in a state that could potentially require
|
56
|
+
# callbacks to be executed?
|
57
|
+
#
|
58
|
+
# @example Is the document in a callback state?
|
59
|
+
# document.in_callback_state?(:update)
|
60
|
+
#
|
61
|
+
# @param [ Symbol ] kind The callback kind.
|
62
|
+
#
|
63
|
+
# @return [ true, false ] If the document is in a callback state.
|
64
|
+
#
|
65
|
+
# @since 3.1.0
|
66
|
+
def in_callback_state?(kind)
|
67
|
+
[ :create, :destroy ].include?(kind) || new_record? || flagged_for_destroy? || changed?
|
68
|
+
end
|
69
|
+
|
55
70
|
# Run only the after callbacks for the specific event.
|
56
71
|
#
|
57
72
|
# @note ActiveSupport does not allow this type of behaviour by default, so
|
@@ -172,8 +187,8 @@ module Mongoid
|
|
172
187
|
#
|
173
188
|
# @since 2.3.0
|
174
189
|
def cascadable_child?(kind, child)
|
175
|
-
return false if kind == :initialize
|
176
|
-
child.
|
190
|
+
return false if kind == :initialize
|
191
|
+
child.callback_executable?(kind) ? child.in_callback_state?(kind) : false
|
177
192
|
end
|
178
193
|
|
179
194
|
# Get the name of the callback that the child should fire. This changes
|
data/lib/mongoid/copyable.rb
CHANGED
@@ -18,17 +18,30 @@ module Mongoid
|
|
18
18
|
#
|
19
19
|
# @return [ Document ] The new document.
|
20
20
|
def clone
|
21
|
-
attrs =
|
22
|
-
if attrs.delete("versions")
|
23
|
-
attrs["version"] = 1
|
24
|
-
end
|
25
|
-
process_localized_attributes(attrs)
|
21
|
+
attrs = clone_document.except("_id")
|
26
22
|
self.class.new(attrs, without_protection: true)
|
27
23
|
end
|
28
24
|
alias :dup :clone
|
29
25
|
|
30
26
|
private
|
31
27
|
|
28
|
+
# Clone the document attributes
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
#
|
32
|
+
# @example clone document
|
33
|
+
# model.clone_document
|
34
|
+
#
|
35
|
+
# @param [ Hash ] dcoument The document with hash format
|
36
|
+
#
|
37
|
+
# @since 3.0.22
|
38
|
+
def clone_document
|
39
|
+
attrs = as_document.__deep_copy__
|
40
|
+
attrs["version"] = 1 if attrs.delete("versions")
|
41
|
+
process_localized_attributes(attrs)
|
42
|
+
attrs
|
43
|
+
end
|
44
|
+
|
32
45
|
# When cloning, if the document has localized fields we need to ensure they
|
33
46
|
# are properly processed in the clone.
|
34
47
|
#
|
data/lib/mongoid/document.rb
CHANGED
@@ -234,7 +234,7 @@ module Mongoid
|
|
234
234
|
raise ArgumentError, "A class which includes Mongoid::Document is expected"
|
235
235
|
end
|
236
236
|
|
237
|
-
became = klass.new(
|
237
|
+
became = klass.new(clone_document, without_protection: true)
|
238
238
|
became.id = id
|
239
239
|
became.instance_variable_set(:@changed_attributes, changed_attributes)
|
240
240
|
became.instance_variable_set(:@errors, errors)
|
@@ -242,6 +242,7 @@ module Mongoid
|
|
242
242
|
became.instance_variable_set(:@destroyed, destroyed?)
|
243
243
|
became.changed_attributes["_type"] = self.class.to_s
|
244
244
|
became._type = klass.to_s
|
245
|
+
IdentityMap.set(became) unless became.new_record?
|
245
246
|
became
|
246
247
|
end
|
247
248
|
|
@@ -67,6 +67,8 @@ module Mongoid
|
|
67
67
|
time = object.__mongoize_time__
|
68
68
|
if time.respond_to?(:sec_fraction)
|
69
69
|
::Time.at(time.to_i, time.sec_fraction * 10**6).utc
|
70
|
+
elsif time.respond_to?(:subsec)
|
71
|
+
::Time.at(time.to_i, time.subsec * 10**6).utc
|
70
72
|
else
|
71
73
|
::Time.at(time.to_i, time.usec).utc
|
72
74
|
end
|
@@ -300,7 +300,7 @@ module Mongoid
|
|
300
300
|
#
|
301
301
|
# @since 2.1.0
|
302
302
|
def criteria(metadata, object, type = nil)
|
303
|
-
apply_ordering(metadata.klass.all_of(_id: { "$in" => object }), metadata)
|
303
|
+
apply_ordering(metadata.klass.all_of(_id: { "$in" => object || [] }), metadata)
|
304
304
|
end
|
305
305
|
|
306
306
|
# Get the criteria that is used to eager load a relation of this
|
data/lib/mongoid/validations.rb
CHANGED
@@ -57,7 +57,7 @@ module Mongoid
|
|
57
57
|
attribute = attr.to_s
|
58
58
|
if relations.has_key?(attribute)
|
59
59
|
begin_validate
|
60
|
-
relation = send(attr)
|
60
|
+
relation = without_autobuild { send(attr) }
|
61
61
|
exit_validate
|
62
62
|
relation.do_or_do_not(:in_memory) || relation
|
63
63
|
elsif fields[attribute].try(:localized?)
|
@@ -16,6 +16,20 @@ module Mongoid
|
|
16
16
|
class UniquenessValidator < ActiveModel::EachValidator
|
17
17
|
include Queryable
|
18
18
|
|
19
|
+
attr_reader :klass
|
20
|
+
|
21
|
+
# Unfortunately, we have to tie Uniqueness validators to a class.
|
22
|
+
#
|
23
|
+
# @example Setup the validator.
|
24
|
+
# UniquenessValidator.new.setup(Person)
|
25
|
+
#
|
26
|
+
# @param [ Class ] klass The class getting validated.
|
27
|
+
#
|
28
|
+
# @since 1.0.0
|
29
|
+
def setup(klass)
|
30
|
+
@klass = klass
|
31
|
+
end
|
32
|
+
|
19
33
|
# Validate the document for uniqueness violations.
|
20
34
|
#
|
21
35
|
# @example Validate the document.
|
@@ -252,7 +266,7 @@ module Mongoid
|
|
252
266
|
#
|
253
267
|
# @since 2.4.10
|
254
268
|
def validate_root(document, attribute, value)
|
255
|
-
criteria = create_criteria(
|
269
|
+
criteria = create_criteria(klass, document, attribute, value)
|
256
270
|
if criteria.with(consistency: :strong).exists?
|
257
271
|
add_error(document, attribute, value)
|
258
272
|
end
|
data/lib/mongoid/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -344,7 +344,8 @@ files:
|
|
344
344
|
- README.md
|
345
345
|
- Rakefile
|
346
346
|
homepage: http://mongoid.org
|
347
|
-
licenses:
|
347
|
+
licenses:
|
348
|
+
- MIT
|
348
349
|
post_install_message:
|
349
350
|
rdoc_options: []
|
350
351
|
require_paths:
|