mongoid 5.4.1 → 6.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +23 -16
- data/lib/mongoid.rb +4 -9
- data/lib/mongoid/atomic.rb +1 -1
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/attributes.rb +9 -11
- data/lib/mongoid/attributes/dynamic.rb +5 -6
- data/lib/mongoid/attributes/nested.rb +1 -1
- data/lib/mongoid/attributes/processing.rb +4 -0
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +37 -1
- data/lib/mongoid/clients.rb +0 -63
- data/lib/mongoid/clients/factory.rb +0 -2
- data/lib/mongoid/clients/options.rb +54 -249
- data/lib/mongoid/clients/storage_options.rb +1 -69
- data/lib/mongoid/composable.rb +26 -2
- data/lib/mongoid/config.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +6 -9
- data/lib/mongoid/contextual/geo_near.rb +2 -3
- data/lib/mongoid/contextual/map_reduce.rb +97 -24
- data/lib/mongoid/contextual/memory.rb +7 -4
- data/lib/mongoid/contextual/mongo.rb +63 -54
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/copyable.rb +19 -19
- data/lib/mongoid/criteria.rb +5 -4
- data/lib/mongoid/criteria/findable.rb +2 -3
- data/lib/mongoid/criteria/includable.rb +63 -16
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +17 -1
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable.rb +86 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +45 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +271 -0
- data/lib/mongoid/criteria/queryable/optional.rb +411 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +662 -0
- data/lib/mongoid/criteria/queryable/selector.rb +196 -0
- data/lib/mongoid/criteria/queryable/smash.rb +103 -0
- data/lib/mongoid/document.rb +9 -23
- data/lib/mongoid/errors.rb +2 -1
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/delete_restriction.rb +2 -2
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/inverse_not_found.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +0 -5
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -3
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/string.rb +4 -3
- data/lib/mongoid/extensions/time.rb +5 -2
- data/lib/mongoid/factory.rb +1 -0
- data/lib/mongoid/fields/foreign_key.rb +2 -2
- data/lib/mongoid/fields/localized.rb +3 -8
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +3 -3
- data/lib/mongoid/indexable.rb +17 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +1 -2
- data/lib/mongoid/interceptable.rb +6 -17
- data/lib/mongoid/loggable.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -10
- data/lib/mongoid/matchable/gt.rb +2 -0
- data/lib/mongoid/matchable/gte.rb +2 -0
- data/lib/mongoid/matchable/lt.rb +2 -0
- data/lib/mongoid/matchable/lte.rb +2 -0
- data/lib/mongoid/persistable.rb +6 -5
- data/lib/mongoid/persistable/creatable.rb +2 -0
- data/lib/mongoid/persistable/deletable.rb +7 -3
- data/lib/mongoid/persistable/settable.rb +3 -16
- data/lib/mongoid/persistable/updatable.rb +10 -12
- data/lib/mongoid/persistence_context.rb +216 -0
- data/lib/mongoid/query_cache.rb +5 -30
- data/lib/mongoid/relations/accessors.rb +6 -2
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/embedded/in.rb +4 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +8 -1
- data/lib/mongoid/relations/bindings/embedded/one.rb +10 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +4 -0
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +28 -18
- data/lib/mongoid/relations/eager.rb +19 -7
- data/lib/mongoid/relations/eager/base.rb +5 -5
- data/lib/mongoid/relations/embedded/batchable.rb +9 -33
- data/lib/mongoid/relations/embedded/in.rb +16 -2
- data/lib/mongoid/relations/embedded/many.rb +23 -8
- data/lib/mongoid/relations/embedded/one.rb +17 -2
- data/lib/mongoid/relations/macros.rb +9 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +1 -1
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +2 -33
- data/lib/mongoid/relations/referenced/in.rb +23 -11
- data/lib/mongoid/relations/referenced/many.rb +24 -16
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +17 -1
- data/lib/mongoid/relations/reflections.rb +3 -5
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +2 -3
- data/lib/mongoid/tasks/database.rb +1 -2
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +2 -4
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -7
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +0 -1
- data/spec/app/models/church.rb +0 -2
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/person.rb +3 -1
- data/spec/app/models/post.rb +0 -1
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +1 -5
- data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +63 -0
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +3 -11
- data/spec/mongoid/clients/options_spec.rb +378 -96
- data/spec/mongoid/clients_spec.rb +207 -170
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +41 -21
- data/spec/mongoid/contextual/atomic_spec.rb +77 -343
- data/spec/mongoid/contextual/map_reduce_spec.rb +119 -111
- data/spec/mongoid/contextual/memory_spec.rb +56 -316
- data/spec/mongoid/contextual/mongo_spec.rb +104 -378
- data/spec/mongoid/copyable_spec.rb +8 -15
- data/spec/mongoid/criteria/modifiable_spec.rb +239 -7
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin/regexp_raw_spec.rb → criteria/queryable/extensions/regexp_spec.rb} +21 -20
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1786 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4159 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +778 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria_spec.rb +45 -63
- data/spec/mongoid/document_spec.rb +21 -88
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +320 -18
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/string_spec.rb +21 -0
- data/spec/mongoid/extensions/time_spec.rb +4 -8
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/fields/localized_spec.rb +0 -91
- data/spec/mongoid/findable_spec.rb +46 -1
- data/spec/mongoid/indexable_spec.rb +6 -46
- data/spec/mongoid/interceptable_spec.rb +49 -10
- data/spec/mongoid/matchable/gt_spec.rb +11 -0
- data/spec/mongoid/matchable/gte_spec.rb +10 -0
- data/spec/mongoid/matchable/lt_spec.rb +11 -0
- data/spec/mongoid/matchable/lte_spec.rb +11 -0
- data/spec/mongoid/matchable_spec.rb +1 -51
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +1 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +6 -2
- data/spec/mongoid/persistable/savable_spec.rb +30 -30
- data/spec/mongoid/persistable/settable_spec.rb +0 -185
- data/spec/mongoid/persistable/updatable_spec.rb +166 -5
- data/spec/mongoid/persistence_context_spec.rb +654 -0
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +89 -65
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -15
- data/spec/mongoid/relations/cyclic_spec.rb +0 -22
- data/spec/mongoid/relations/embedded/many_spec.rb +9 -41
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +395 -7
- data/spec/mongoid/relations/proxy_spec.rb +3 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +6 -29
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +6 -29
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +0 -12
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +16 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/spec_helper.rb +10 -10
- metadata +536 -479
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -20
- data/lib/mongoid/extensions/decimal128.rb +0 -39
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -44
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
@@ -7,6 +7,24 @@ module Mongoid
|
|
7
7
|
# many-to-many between documents in different collections.
|
8
8
|
class ManyToMany < Many
|
9
9
|
|
10
|
+
# The allowed options when defining this relation.
|
11
|
+
#
|
12
|
+
# @return [ Array<Symbol> ] The allowed options when defining this relation.
|
13
|
+
#
|
14
|
+
# @since 6.0.0
|
15
|
+
VALID_OPTIONS = [
|
16
|
+
:after_add,
|
17
|
+
:after_remove,
|
18
|
+
:autosave,
|
19
|
+
:before_add,
|
20
|
+
:before_remove,
|
21
|
+
:dependent,
|
22
|
+
:foreign_key,
|
23
|
+
:index,
|
24
|
+
:order,
|
25
|
+
:primary_key
|
26
|
+
].freeze
|
27
|
+
|
10
28
|
# Appends a document or array of documents to the relation. Will set
|
11
29
|
# the parent and update the index in the process.
|
12
30
|
#
|
@@ -19,7 +37,7 @@ module Mongoid
|
|
19
37
|
# @example Concat with other documents.
|
20
38
|
# person.posts.concat([ post_one, post_two ])
|
21
39
|
#
|
22
|
-
# @param [ Document, Array<Document> ] args Any number of documents.
|
40
|
+
# @param [ Document, Array<Document> ] *args Any number of documents.
|
23
41
|
#
|
24
42
|
# @return [ Array<Document> ] The loaded docs.
|
25
43
|
#
|
@@ -439,18 +457,7 @@ module Mongoid
|
|
439
457
|
#
|
440
458
|
# @since 2.1.0
|
441
459
|
def valid_options
|
442
|
-
|
443
|
-
:after_add,
|
444
|
-
:after_remove,
|
445
|
-
:autosave,
|
446
|
-
:before_add,
|
447
|
-
:before_remove,
|
448
|
-
:dependent,
|
449
|
-
:foreign_key,
|
450
|
-
:index,
|
451
|
-
:order,
|
452
|
-
:primary_key
|
453
|
-
]
|
460
|
+
VALID_OPTIONS
|
454
461
|
end
|
455
462
|
|
456
463
|
# Get the default validation setting for the relation. Determines if
|
@@ -7,6 +7,20 @@ module Mongoid
|
|
7
7
|
# one-to-one between documents in different collections.
|
8
8
|
class One < Relations::One
|
9
9
|
|
10
|
+
# The allowed options when defining this relation.
|
11
|
+
#
|
12
|
+
# @return [ Array<Symbol> ] The allowed options when defining this relation.
|
13
|
+
#
|
14
|
+
# @since 6.0.0
|
15
|
+
VALID_OPTIONS = [
|
16
|
+
:as,
|
17
|
+
:autobuild,
|
18
|
+
:autosave,
|
19
|
+
:dependent,
|
20
|
+
:foreign_key,
|
21
|
+
:primary_key
|
22
|
+
].freeze
|
23
|
+
|
10
24
|
# Instantiate a new references_one relation. Will set the foreign key
|
11
25
|
# and the base on the inverse object.
|
12
26
|
#
|
@@ -69,6 +83,8 @@ module Mongoid
|
|
69
83
|
# @example Get the binding.
|
70
84
|
# relation.binding([ address ])
|
71
85
|
#
|
86
|
+
# @param [ Document ] new_target The new target of the relation.
|
87
|
+
#
|
72
88
|
# @return [ Binding ] The binding object.
|
73
89
|
def binding
|
74
90
|
Bindings::Referenced::One.new(base, target, __metadata)
|
@@ -254,7 +270,7 @@ module Mongoid
|
|
254
270
|
#
|
255
271
|
# @since 2.1.0
|
256
272
|
def valid_options
|
257
|
-
|
273
|
+
VALID_OPTIONS
|
258
274
|
end
|
259
275
|
|
260
276
|
# Get the default validation setting for the relation. Determines if
|
@@ -24,7 +24,7 @@ module Mongoid
|
|
24
24
|
# @example Find multiple relation metadata by macro.
|
25
25
|
# person.reflect_on_all_associations(:embeds_many)
|
26
26
|
#
|
27
|
-
# @param [ Array<Symbol> ] macros The relation macros.
|
27
|
+
# @param [ Array<String, Symbol> ] *macros The relation macros.
|
28
28
|
#
|
29
29
|
# @return [ Array<Metadata> ] The matching relation metadata.
|
30
30
|
def reflect_on_all_associations(*macros)
|
@@ -50,13 +50,11 @@ module Mongoid
|
|
50
50
|
# @example Find multiple relation metadata by macro.
|
51
51
|
# Person.reflect_on_all_associations(:embeds_many)
|
52
52
|
#
|
53
|
-
# @param [ Array<Symbol> ] macros The relation macros.
|
53
|
+
# @param [ Array<String, Symbol> ] *macros The relation macros.
|
54
54
|
#
|
55
55
|
# @return [ Array<Metadata> ] The matching relation metadata.
|
56
56
|
def reflect_on_all_associations(*macros)
|
57
|
-
|
58
|
-
association_reflections.select! { |reflection| macros.include?(reflection.macro) } unless macros.empty?
|
59
|
-
association_reflections
|
57
|
+
relations.values.select { |meta| macros.include?(meta.macro) }
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
@@ -78,7 +78,7 @@ module Mongoid
|
|
78
78
|
# @return [ Symbol ] The method name.
|
79
79
|
def define_relation_touch_method(name)
|
80
80
|
method_name = "touch_#{name}_after_create_or_destroy"
|
81
|
-
class_eval <<-TOUCH
|
81
|
+
class_eval <<-TOUCH
|
82
82
|
def #{method_name}
|
83
83
|
without_autobuild do
|
84
84
|
relation = __send__(:#{name})
|
data/lib/mongoid/reloadable.rb
CHANGED
data/lib/mongoid/scopable.rb
CHANGED
@@ -80,7 +80,7 @@ module Mongoid
|
|
80
80
|
# default_scope ->{ where(active: true) }
|
81
81
|
# end
|
82
82
|
#
|
83
|
-
# @param [ Proc, Criteria ]
|
83
|
+
# @param [ Proc, Criteria ] scope The default scope.
|
84
84
|
#
|
85
85
|
# @raise [ Errors::InvalidScope ] If the scope is not a proc or criteria.
|
86
86
|
#
|
@@ -117,7 +117,7 @@ module Mongoid
|
|
117
117
|
# @since 3.0.0
|
118
118
|
def queryable
|
119
119
|
crit = Threaded.current_scope(self) || Criteria.new(self)
|
120
|
-
crit.embedded = true if
|
120
|
+
crit.embedded = true if crit.klass.embedded?
|
121
121
|
crit
|
122
122
|
end
|
123
123
|
|
@@ -136,7 +136,7 @@ module Mongoid
|
|
136
136
|
# end
|
137
137
|
#
|
138
138
|
# @param [ Symbol ] name The name of the scope.
|
139
|
-
# @param [ Proc ]
|
139
|
+
# @param [ Proc ] conditions The conditions of the scope.
|
140
140
|
#
|
141
141
|
# @raise [ Errors::InvalidScope ] If the scope is not a proc.
|
142
142
|
# @raise [ Errors::ScopeOverwrite ] If the scope name already exists.
|
data/lib/mongoid/serializable.rb
CHANGED
@@ -138,7 +138,7 @@ module Mongoid
|
|
138
138
|
# @example Get the relation names.
|
139
139
|
# document.relation_names(:include => [ :addresses ])
|
140
140
|
#
|
141
|
-
# @param [ Hash, Symbol, Array<Symbol
|
141
|
+
# @param [ Hash, Symbol, Array<Symbol ] inclusions The inclusions.
|
142
142
|
#
|
143
143
|
# @return [ Array<Symbol> ] The names of the included relations.
|
144
144
|
#
|
@@ -153,8 +153,7 @@ module Mongoid
|
|
153
153
|
# @example Get the relation options.
|
154
154
|
# document.relation_names(:include => [ :addresses ])
|
155
155
|
#
|
156
|
-
# @param [ Hash, Symbol, Array<Symbol
|
157
|
-
# @param [ Hash ] options The options.
|
156
|
+
# @param [ Hash, Symbol, Array<Symbol ] inclusions The inclusions.
|
158
157
|
# @param [ Symbol ] name The name of the relation.
|
159
158
|
#
|
160
159
|
# @return [ Hash ] The options for the relation.
|
@@ -36,8 +36,7 @@ module Mongoid
|
|
36
36
|
# @example Return the list of unused indexes.
|
37
37
|
# Mongoid::Tasks::Database.undefined_indexes
|
38
38
|
#
|
39
|
-
# @return
|
40
|
-
#
|
39
|
+
# @return Hash{Class => Array(Hash)} The list of undefined indexes by model.
|
41
40
|
def undefined_indexes(models = ::Mongoid.models)
|
42
41
|
undefined_by_model = {}
|
43
42
|
|
data/lib/mongoid/threaded.rb
CHANGED
@@ -64,7 +64,7 @@ module Mongoid
|
|
64
64
|
# @example Set the global database override.
|
65
65
|
# Threaded.database_override = :testing
|
66
66
|
#
|
67
|
-
# @param [ String, Symbol ]
|
67
|
+
# @param [ String, Symbol ] The global override name.
|
68
68
|
#
|
69
69
|
# @return [ String, Symbol ] The override.
|
70
70
|
#
|
@@ -180,7 +180,7 @@ module Mongoid
|
|
180
180
|
# @example Set the global client override.
|
181
181
|
# Threaded.client_override = :testing
|
182
182
|
#
|
183
|
-
# @param [ String, Symbol ]
|
183
|
+
# @param [ String, Symbol ] The global override name.
|
184
184
|
#
|
185
185
|
# @return [ String, Symbol ] The override.
|
186
186
|
#
|
@@ -304,7 +304,7 @@ module Mongoid
|
|
304
304
|
# @example Get all autosaves.
|
305
305
|
# Threaded.autosaves_for(Person)
|
306
306
|
#
|
307
|
-
# @param [ Class ]
|
307
|
+
# @param [ Class ] The class to check.
|
308
308
|
#
|
309
309
|
# @return [ Array ] The current autosaves.
|
310
310
|
#
|
@@ -317,7 +317,7 @@ module Mongoid
|
|
317
317
|
# @example Get all validations.
|
318
318
|
# Threaded.validations_for(Person)
|
319
319
|
#
|
320
|
-
# @param [ Class ]
|
320
|
+
# @param [ Class ] The class to check.
|
321
321
|
#
|
322
322
|
# @return [ Array ] The current validations.
|
323
323
|
#
|
data/lib/mongoid/traversable.rb
CHANGED
data/lib/mongoid/validatable.rb
CHANGED
@@ -144,7 +144,7 @@ module Mongoid
|
|
144
144
|
# @example Validate with a specific validator.
|
145
145
|
# validates_with MyValidator, on: :create
|
146
146
|
#
|
147
|
-
# @param [ Class<Array>, Hash ] args The validator classes and options.
|
147
|
+
# @param [ Class<Array>, Hash ] *args The validator classes and options.
|
148
148
|
#
|
149
149
|
# @note See ActiveModel::Validations::With for full options. This is
|
150
150
|
# overridden to add autosave functionality when presence validation is
|
@@ -17,8 +17,7 @@ module Mongoid
|
|
17
17
|
# validates_associated :name, :addresses
|
18
18
|
# end
|
19
19
|
#
|
20
|
-
# @param [ Array ] args The arguments to pass to the validator.
|
21
|
-
#
|
20
|
+
# @param [ Array ] *args The arguments to pass to the validator.
|
22
21
|
def validates_associated(*args)
|
23
22
|
validates_with(AssociatedValidator, _merge_attributes(args))
|
24
23
|
end
|
@@ -35,8 +34,7 @@ module Mongoid
|
|
35
34
|
# validates_uniqueness_of :title
|
36
35
|
# end
|
37
36
|
#
|
38
|
-
# @param [ Array ] args The arguments to pass to the validator.
|
39
|
-
#
|
37
|
+
# @param [ Array ] *args The arguments to pass to the validator.
|
40
38
|
def validates_uniqueness_of(*args)
|
41
39
|
validates_with(UniquenessValidator, _merge_attributes(args))
|
42
40
|
end
|
@@ -169,7 +169,6 @@ module Mongoid
|
|
169
169
|
name = document.database_field_name(item)
|
170
170
|
criteria = criteria.where(item => document.attributes[name])
|
171
171
|
end
|
172
|
-
criteria = criteria.with(document.persistence_options)
|
173
172
|
criteria
|
174
173
|
end
|
175
174
|
|
@@ -274,7 +273,7 @@ module Mongoid
|
|
274
273
|
criteria = create_criteria(klass, document, attribute, value)
|
275
274
|
criteria = criteria.merge(options[:conditions].call) if options[:conditions]
|
276
275
|
|
277
|
-
if criteria.
|
276
|
+
if criteria.read(mode: :primary).exists?
|
278
277
|
add_error(document, attribute, value)
|
279
278
|
end
|
280
279
|
end
|
data/lib/mongoid/version.rb
CHANGED
@@ -38,7 +38,8 @@ development:
|
|
38
38
|
# on 2.4 and 2.6 is :plain)
|
39
39
|
# auth_mech: :scram
|
40
40
|
|
41
|
-
# The database or source to authenticate the user against.
|
41
|
+
# The database or source to authenticate the user against.
|
42
|
+
# (default: the database specified above or admin)
|
42
43
|
# auth_source: admin
|
43
44
|
|
44
45
|
# Force a the driver cluster to behave in a certain manner instead of auto-
|
@@ -50,8 +51,8 @@ development:
|
|
50
51
|
# via ismaster commands. (default: 10)
|
51
52
|
# heartbeat_frequency: 10
|
52
53
|
|
53
|
-
# The time in seconds for selecting servers for a near read preference. (default:
|
54
|
-
# local_threshold:
|
54
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
55
|
+
# local_threshold: 5
|
55
56
|
|
56
57
|
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
57
58
|
# server_selection_timeout: 30
|
@@ -130,10 +131,6 @@ development:
|
|
130
131
|
# environment. The Mongoid logger will be set to the Rails logger
|
131
132
|
# otherwise.(default: :info)
|
132
133
|
# log_level: :info
|
133
|
-
|
134
|
-
# Application name that is printed to the mongodb logs upon establishing a
|
135
|
-
# connection in server versions >= 3.4. Note that the name cannot exceed 128 bytes.
|
136
|
-
# app_name: MyApplicationName
|
137
134
|
test:
|
138
135
|
clients:
|
139
136
|
default:
|
data/spec/app/models/album.rb
CHANGED
data/spec/app/models/artist.rb
CHANGED
@@ -13,16 +13,37 @@ class Artist
|
|
13
13
|
after_create :create_songs
|
14
14
|
before_save :before_save_stub
|
15
15
|
before_destroy :before_destroy_stub
|
16
|
+
before_update :before_update_stub
|
16
17
|
|
17
18
|
protected
|
18
19
|
def before_create_stub
|
19
20
|
true
|
20
21
|
end
|
21
22
|
|
23
|
+
def before_update_stub
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def before_update_fail_stub
|
28
|
+
throw(:abort)
|
29
|
+
end
|
30
|
+
|
31
|
+
def before_save_fail_stub
|
32
|
+
throw(:abort)
|
33
|
+
end
|
34
|
+
|
35
|
+
def before_create_fail_stub
|
36
|
+
throw(:abort)
|
37
|
+
end
|
38
|
+
|
22
39
|
def before_save_stub
|
23
40
|
true
|
24
41
|
end
|
25
42
|
|
43
|
+
def before_destroy_fail_stub
|
44
|
+
throw(:abort)
|
45
|
+
end
|
46
|
+
|
26
47
|
def before_destroy_stub
|
27
48
|
true
|
28
49
|
end
|
data/spec/app/models/band.rb
CHANGED
@@ -13,7 +13,6 @@ class Band
|
|
13
13
|
field :upserted, type: Mongoid::Boolean, default: false
|
14
14
|
field :created, type: DateTime
|
15
15
|
field :sales, type: BigDecimal
|
16
|
-
field :decimal, type: BSON::Decimal128
|
17
16
|
field :y, as: :years, type: Integer
|
18
17
|
field :founded, type: Date
|
19
18
|
field :deleted, type: Boolean
|
data/spec/app/models/church.rb
CHANGED
data/spec/app/models/oscar.rb
CHANGED
data/spec/app/models/person.rb
CHANGED
@@ -36,6 +36,7 @@ class Person
|
|
36
36
|
field :overridden_setter, type: String
|
37
37
|
field :arrays, type: Array
|
38
38
|
field :range, type: Range
|
39
|
+
field :species, type: Symbol
|
39
40
|
|
40
41
|
index age: 1
|
41
42
|
index addresses: 1
|
@@ -134,7 +135,8 @@ class Person
|
|
134
135
|
self.score_without_rescoring = score
|
135
136
|
end
|
136
137
|
|
137
|
-
|
138
|
+
alias_method :score_without_rescoring=, :score=
|
139
|
+
alias_method :score=, :score_with_rescoring=
|
138
140
|
|
139
141
|
def update_addresses
|
140
142
|
addresses.each do |address|
|
data/spec/app/models/post.rb
CHANGED
@@ -11,7 +11,6 @@ class Post
|
|
11
11
|
|
12
12
|
belongs_to :person, counter_cache: true
|
13
13
|
belongs_to :author, foreign_key: :author_id, class_name: "User"
|
14
|
-
belongs_to :post_genre, foreign_key: :genre_id, counter_cache: true
|
15
14
|
has_and_belongs_to_many :tags, before_add: :before_add_tag, after_add: :after_add_tag, before_remove: :before_remove_tag, after_remove: :after_remove_tag
|
16
15
|
has_many :videos, validate: false
|
17
16
|
has_many :roles, validate: false
|