mongoid 3.0.4 → 3.0.5
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.
- data/CHANGELOG.md +32 -1
- data/lib/config/locales/en.yml +0 -8
- data/lib/mongoid/atomic.rb +23 -0
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/dirty.rb +2 -1
- data/lib/mongoid/errors.rb +0 -1
- data/lib/mongoid/extensions/time_with_zone.rb +1 -0
- data/lib/mongoid/persistence.rb +1 -1
- data/lib/mongoid/relations/embedded/one.rb +1 -0
- data/lib/mongoid/relations/metadata.rb +3 -1
- data/lib/mongoid/relations/referenced/many.rb +6 -1
- data/lib/mongoid/relations/referenced/many_to_many.rb +3 -0
- data/lib/mongoid/relations/synchronization.rb +4 -1
- data/lib/mongoid/reloading.rb +1 -0
- data/lib/mongoid/scoping.rb +20 -1
- data/lib/mongoid/validations/presence.rb +18 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid_generator.rb +4 -0
- metadata +3 -4
- data/lib/mongoid/errors/unsupported_version.rb +0 -20
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,38 @@
|
|
3
3
|
For instructions on upgrading to newer versions, visit
|
4
4
|
[mongoid.org](http://mongoid.org/docs/upgrading.html).
|
5
5
|
|
6
|
-
## 3.0.
|
6
|
+
## 3.0.5 (branch 3.0.0-stable)
|
7
|
+
|
8
|
+
* \#2313 Fixed deserialization of `nil` `TimeWithZone` fields. (nagachika)
|
9
|
+
|
10
|
+
* \#2311 `Document#changes` no longer returns `nil` values for Array and Hash
|
11
|
+
fields that were only accessed and didn't actually change. Regression from 2.4.x.
|
12
|
+
|
13
|
+
* \#2310 Setting a many to many duplicate successively in memory no longer clears
|
14
|
+
the inverse foreign keys.
|
15
|
+
|
16
|
+
* \#2309 Allow embeds_one relations to be set with hashes more than just the
|
17
|
+
initial set.
|
18
|
+
|
19
|
+
* \#2308 Ensure documents retrieved via `#find` on `has_many` and
|
20
|
+
`has_and_belongs_to_many` relations are kept in memory.
|
21
|
+
|
22
|
+
* \#2304 Default scopes now properly merge instead of overwrite when more
|
23
|
+
than one is defined as per expectations with AR. (Kirill Maksimov)
|
24
|
+
|
25
|
+
* \#2300 Ensure reloading refreshes the document in the identity map.
|
26
|
+
|
27
|
+
* \#2298 Protect against many to many relations pulling a null set of ids.
|
28
|
+
(Jonathan Hyman)
|
29
|
+
|
30
|
+
* \#2291 Fixed touch operations only to update the timestamp and the optional
|
31
|
+
field, no matter what the other changes on the document are.
|
32
|
+
|
33
|
+
* \#1091 Allow presence validation to pass if the value is `false`.
|
34
|
+
|
35
|
+
### Resolved Issues
|
36
|
+
|
37
|
+
## 3.0.4
|
7
38
|
|
8
39
|
### Resolved Issues
|
9
40
|
|
data/lib/config/locales/en.yml
CHANGED
@@ -440,14 +440,6 @@ en:
|
|
440
440
|
since the child could potentially reference a nonexistant parent."
|
441
441
|
resolution: "Make sure to only use create or create! when the parent
|
442
442
|
document %{base} is persisted."
|
443
|
-
unsupported_version:
|
444
|
-
message: "MongoDB %{version} not supported, please upgrade to
|
445
|
-
%{mongo_version}."
|
446
|
-
summary: "Mongoid is relying on features that were introduced in
|
447
|
-
MongoDB %{mongo_version} and would cause unexpected behaviour or errors
|
448
|
-
on version %{version}."
|
449
|
-
resolution: "Upgrade your MongoDB instances or keep Mongoid on your
|
450
|
-
previous version."
|
451
443
|
unsupported_javascript:
|
452
444
|
message: "Executing Javascript $where selector on an embedded criteria
|
453
445
|
is not supported."
|
data/lib/mongoid/atomic.rb
CHANGED
@@ -335,5 +335,28 @@ module Mongoid
|
|
335
335
|
mods.add_to_set(doc.atomic_array_add_to_sets)
|
336
336
|
mods.pull_all(doc.atomic_array_pulls)
|
337
337
|
end
|
338
|
+
|
339
|
+
# Get the atomic updates for a touch operation. Should only include the
|
340
|
+
# updated_at field and the optional extra field.
|
341
|
+
#
|
342
|
+
# @api private
|
343
|
+
#
|
344
|
+
# @example Get the touch atomic updates.
|
345
|
+
# document.touch_atomic_updates
|
346
|
+
#
|
347
|
+
# @param [ Symbol ] field The optional field.
|
348
|
+
#
|
349
|
+
# @return [ Hash ] The atomic updates.
|
350
|
+
#
|
351
|
+
# @since 3.0.6
|
352
|
+
def touch_atomic_updates(field = nil)
|
353
|
+
updates = atomic_updates
|
354
|
+
return {} unless atomic_updates.has_key?("$set")
|
355
|
+
touches = {}
|
356
|
+
updates["$set"].each_pair do |key, value|
|
357
|
+
touches.merge!({ key => value }) if key =~ /updated_at|#{field}/
|
358
|
+
end
|
359
|
+
{ "$set" => touches }
|
360
|
+
end
|
338
361
|
end
|
339
362
|
end
|
data/lib/mongoid/config.rb
CHANGED
@@ -21,6 +21,7 @@ module Mongoid
|
|
21
21
|
option :protect_sensitive_fields, default: true
|
22
22
|
option :raise_not_found_error, default: true
|
23
23
|
option :scope_overwrite_exception, default: false
|
24
|
+
# @todo: Remove at 4.0
|
24
25
|
option :skip_version_check, default: false
|
25
26
|
option :use_activesupport_time_zone, default: true
|
26
27
|
option :use_utc, default: false
|
data/lib/mongoid/dirty.rb
CHANGED
data/lib/mongoid/errors.rb
CHANGED
@@ -36,7 +36,6 @@ require "mongoid/errors/too_many_nested_attribute_records"
|
|
36
36
|
require "mongoid/errors/unknown_attribute"
|
37
37
|
require "mongoid/errors/unsaved_document"
|
38
38
|
require "mongoid/errors/unsupported_javascript"
|
39
|
-
require "mongoid/errors/unsupported_version"
|
40
39
|
require "mongoid/errors/validations"
|
41
40
|
require "mongoid/errors/versioning_not_on_root"
|
42
41
|
require "mongoid/errors/delete_restriction"
|
data/lib/mongoid/persistence.rb
CHANGED
@@ -120,7 +120,7 @@ module Mongoid
|
|
120
120
|
current = Time.now
|
121
121
|
write_attribute(:updated_at, current) if fields["updated_at"]
|
122
122
|
write_attribute(field, current) if field
|
123
|
-
_root.collection.find(atomic_selector).update(
|
123
|
+
_root.collection.find(atomic_selector).update(touch_atomic_updates(field))
|
124
124
|
without_autobuild do
|
125
125
|
touchables.each { |name| send(name).try(:touch) }
|
126
126
|
end
|
@@ -1120,7 +1120,9 @@ module Mongoid
|
|
1120
1120
|
if other
|
1121
1121
|
matches = []
|
1122
1122
|
other.class.relations.values.each do |meta|
|
1123
|
-
|
1123
|
+
if meta.as == name && meta.class_name == inverse_class_name
|
1124
|
+
matches.push(meta.name)
|
1125
|
+
end
|
1124
1126
|
end
|
1125
1127
|
matches
|
1126
1128
|
end
|
@@ -185,13 +185,18 @@ module Mongoid
|
|
185
185
|
# @example Find by multiple ids.
|
186
186
|
# person.posts.find([ Moped::BSON::ObjectId.new, Moped::BSON::ObjectId.new ])
|
187
187
|
#
|
188
|
+
# @note This will keep matching documents in memory for iteration
|
189
|
+
# later.
|
190
|
+
#
|
188
191
|
# @param [ Moped::BSON::ObjectId, Array<Moped::BSON::ObjectId> ] arg The ids.
|
189
192
|
#
|
190
193
|
# @return [ Document, Criteria ] The matching document(s).
|
191
194
|
#
|
192
195
|
# @since 2.0.0.beta.1
|
193
196
|
def find(*args)
|
194
|
-
criteria.find(*args)
|
197
|
+
matching = criteria.find(*args)
|
198
|
+
Array(matching).each { |doc| target.push(doc) }
|
199
|
+
matching
|
195
200
|
end
|
196
201
|
|
197
202
|
# Instantiate a new references_many relation. Will set the foreign key
|
@@ -59,7 +59,10 @@ module Mongoid
|
|
59
59
|
#
|
60
60
|
# @since 2.2.1
|
61
61
|
def remove_inverse_keys(meta)
|
62
|
-
|
62
|
+
foreign_keys = send(meta.foreign_key)
|
63
|
+
unless foreign_keys.nil? || foreign_keys.empty?
|
64
|
+
meta.criteria(foreign_keys, self.class).pull(meta.inverse_foreign_key, id)
|
65
|
+
end
|
63
66
|
end
|
64
67
|
|
65
68
|
# Update the inverse keys for the relation.
|
data/lib/mongoid/reloading.rb
CHANGED
data/lib/mongoid/scoping.rb
CHANGED
@@ -40,7 +40,7 @@ module Mongoid
|
|
40
40
|
# @since 1.0.0
|
41
41
|
def default_scope(value)
|
42
42
|
check_scope_validity(value)
|
43
|
-
self.default_scoping = value
|
43
|
+
self.default_scoping = process_default_scope(value)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Is the class able to have the default scope applied?
|
@@ -284,6 +284,25 @@ module Mongoid
|
|
284
284
|
SCOPE
|
285
285
|
end
|
286
286
|
|
287
|
+
# Process the default scope value. If one already exists, we merge the
|
288
|
+
# new one into the old one.
|
289
|
+
#
|
290
|
+
# @api private
|
291
|
+
#
|
292
|
+
# @example Process the default scope.
|
293
|
+
# Model.process_default_scope(value)
|
294
|
+
#
|
295
|
+
# @param [ Criteria, Proc ] value The default scope value.
|
296
|
+
#
|
297
|
+
# @since 3.0.5
|
298
|
+
def process_default_scope(value)
|
299
|
+
if existing = default_scoping
|
300
|
+
->{ existing.call.merge(value.to_proc.call) }
|
301
|
+
else
|
302
|
+
value.to_proc
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
287
306
|
# Strip the default scope from the provided value, if it is a criteria.
|
288
307
|
# This is used by named scopes - they should not have the default scoping
|
289
308
|
# applied to them.
|
@@ -33,14 +33,14 @@ module Mongoid
|
|
33
33
|
attribute,
|
34
34
|
:blank_in_locale,
|
35
35
|
options.merge(location: _locale)
|
36
|
-
) if _value
|
36
|
+
) if not_present?(_value)
|
37
37
|
end
|
38
38
|
elsif document.relations.has_key?(attribute.to_s)
|
39
39
|
if relation_or_fk_missing?(document, attribute, value)
|
40
40
|
document.errors.add(attribute, :blank, options)
|
41
41
|
end
|
42
42
|
else
|
43
|
-
document.errors.add(attribute, :blank, options) if value
|
43
|
+
document.errors.add(attribute, :blank, options) if not_present?(value)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -65,6 +65,22 @@ module Mongoid
|
|
65
65
|
metadata = doc.relations[attr.to_s]
|
66
66
|
metadata.stores_foreign_key? && doc.send(metadata.foreign_key).blank?
|
67
67
|
end
|
68
|
+
|
69
|
+
# For guarding against false values.
|
70
|
+
#
|
71
|
+
# @api private
|
72
|
+
#
|
73
|
+
# @example Is the value not present?
|
74
|
+
# validator.not_present?(value)
|
75
|
+
#
|
76
|
+
# @param [ Object ] value The value.
|
77
|
+
#
|
78
|
+
# @return [ true, false ] If the value is not present.
|
79
|
+
#
|
80
|
+
# @since 3.0.5
|
81
|
+
def not_present?(value)
|
82
|
+
value.blank? && value != false
|
83
|
+
end
|
68
84
|
end
|
69
85
|
end
|
70
86
|
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.5
|
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: 2012-08-
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -156,7 +156,6 @@ files:
|
|
156
156
|
- lib/mongoid/errors/unknown_attribute.rb
|
157
157
|
- lib/mongoid/errors/unsaved_document.rb
|
158
158
|
- lib/mongoid/errors/unsupported_javascript.rb
|
159
|
-
- lib/mongoid/errors/unsupported_version.rb
|
160
159
|
- lib/mongoid/errors/validations.rb
|
161
160
|
- lib/mongoid/errors/versioning_not_on_root.rb
|
162
161
|
- lib/mongoid/errors.rb
|
@@ -354,7 +353,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
354
353
|
version: '0'
|
355
354
|
segments:
|
356
355
|
- 0
|
357
|
-
hash: -
|
356
|
+
hash: -1770994134498643287
|
358
357
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
359
358
|
none: false
|
360
359
|
requirements:
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid
|
3
|
-
module Errors
|
4
|
-
|
5
|
-
# Raised when the database version is not supported by Mongoid.
|
6
|
-
#
|
7
|
-
# @example Create the error.
|
8
|
-
# UnsupportedVersion.new(Mongo::ServerVersion.new("1.3.1"))
|
9
|
-
class UnsupportedVersion < MongoidError
|
10
|
-
def initialize(version)
|
11
|
-
super(
|
12
|
-
compose_message(
|
13
|
-
"unsupported_version",
|
14
|
-
{ version: version, mongo_version: Mongoid::MONGODB_VERSION }
|
15
|
-
)
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|