mongoid 2.0.0.beta.17 → 2.0.0.beta.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid.rb +0 -1
- data/lib/mongoid/atomicity.rb +26 -2
- data/lib/mongoid/paranoia.rb +1 -1
- data/lib/mongoid/validations/associated.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +1 -1
- metadata +6 -6
data/lib/mongoid.rb
CHANGED
@@ -31,7 +31,6 @@ require "active_support/time_with_zone"
|
|
31
31
|
require "active_model"
|
32
32
|
require "active_model/callbacks"
|
33
33
|
require "active_model/conversion"
|
34
|
-
require "active_model/deprecated_error_methods"
|
35
34
|
require "active_model/errors"
|
36
35
|
require "active_model/mass_assignment_security"
|
37
36
|
require "active_model/naming"
|
data/lib/mongoid/atomicity.rb
CHANGED
@@ -20,9 +20,26 @@ module Mongoid #:nodoc:
|
|
20
20
|
_children.inject({ "$set" => _sets, "$pushAll" => {}, :other => {} }) do |updates, child|
|
21
21
|
changes = child._sets
|
22
22
|
updates["$set"].update(changes)
|
23
|
-
|
23
|
+
unless changes.empty?
|
24
|
+
processed[child._conficting_modification_key] = true
|
25
|
+
end
|
24
26
|
|
25
|
-
|
27
|
+
# MongoDB does not allow "conflicting modifications" to be
|
28
|
+
# performed in a single operation. Conflicting modifications are
|
29
|
+
# detected by the 'haveConflictingMod' function in MongoDB.
|
30
|
+
# Examination of the code suggests that two modifications (a $set
|
31
|
+
# and a $pushAll, for example) conflict if (1) the key paths being
|
32
|
+
# modified are equal or (2) one key path is a prefix of the other.
|
33
|
+
# So a $set of 'addresses.0.street' will conflict with a $pushAll
|
34
|
+
# to 'addresses', and we will need to split our update into two
|
35
|
+
# pieces. We do not, however, attempt to match MongoDB's logic
|
36
|
+
# exactly. Instead, we assume that two updates conflict if the
|
37
|
+
# first component of the two key paths matches.
|
38
|
+
if processed.has_key?(child._conficting_modification_key)
|
39
|
+
target = :other
|
40
|
+
else
|
41
|
+
target = "$pushAll"
|
42
|
+
end
|
26
43
|
|
27
44
|
child._pushes.each do |attr, val|
|
28
45
|
if updates[target].has_key?(attr)
|
@@ -38,6 +55,13 @@ module Mongoid #:nodoc:
|
|
38
55
|
end
|
39
56
|
|
40
57
|
protected
|
58
|
+
# Get the key used to check for conflicting modifications. For now, we
|
59
|
+
# just use the first component of _path, and discard the first period
|
60
|
+
# and everything that follows.
|
61
|
+
def _conficting_modification_key
|
62
|
+
_path.sub(/\..*/, '')
|
63
|
+
end
|
64
|
+
|
41
65
|
# Get all the push attributes that need to occur.
|
42
66
|
def _pushes
|
43
67
|
(new_record? && embedded_many? && !_parent.new_record?) ? { _path => raw_attributes } : {}
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -25,7 +25,7 @@ module Mongoid #:nodoc:
|
|
25
25
|
def validate_each(document, attribute, value)
|
26
26
|
values = value.is_a?(Array) ? value : [ value ]
|
27
27
|
return if values.collect { |doc| doc.nil? || doc.valid? }.all?
|
28
|
-
document.errors.add(attribute, :invalid, options.merge
|
28
|
+
document.errors.add(attribute, :invalid, options.merge(:value => value))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid/versioning.rb
CHANGED
@@ -28,7 +28,7 @@ module Mongoid #:nodoc:
|
|
28
28
|
if last_version
|
29
29
|
self.versions << last_version.clone
|
30
30
|
self.versions.shift if self.class.version_max.present? && self.versions.length > self.class.version_max
|
31
|
-
self.version = version + 1
|
31
|
+
self.version = (version || 1 ) + 1
|
32
32
|
@modifications["versions"] = [ nil, @attributes["versions"] ] if @modifications
|
33
33
|
end
|
34
34
|
end
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 2.0.0.beta.
|
10
|
+
- 18
|
11
|
+
version: 2.0.0.beta.18
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Durran Jordan
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-09-14 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -136,8 +136,8 @@ dependencies:
|
|
136
136
|
- 0
|
137
137
|
- 0
|
138
138
|
- beta
|
139
|
-
-
|
140
|
-
version: 2.0.0.beta.
|
139
|
+
- 22
|
140
|
+
version: 2.0.0.beta.22
|
141
141
|
type: :development
|
142
142
|
prerelease: false
|
143
143
|
version_requirements: *id008
|
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
344
344
|
requirements:
|
345
345
|
- - ">="
|
346
346
|
- !ruby/object:Gem::Version
|
347
|
-
hash:
|
347
|
+
hash: -407375290619395717
|
348
348
|
segments:
|
349
349
|
- 0
|
350
350
|
version: "0"
|