mongoid 6.4.8 → 7.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/Rakefile +0 -26
- data/lib/config/locales/en.yml +17 -21
- data/lib/mongoid.rb +2 -2
- data/lib/mongoid/association.rb +150 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +116 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +27 -53
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +18 -52
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +31 -58
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +159 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
- data/lib/mongoid/association/referenced/has_many.rb +273 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +479 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +577 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +415 -0
- data/lib/mongoid/association/touchable.rb +97 -0
- data/lib/mongoid/atomic.rb +6 -6
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/attributes.rb +2 -1
- data/lib/mongoid/attributes/nested.rb +10 -10
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/clients.rb +0 -2
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/storage_options.rb +0 -1
- data/lib/mongoid/composable.rb +3 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +3 -6
- data/lib/mongoid/contextual/map_reduce.rb +3 -7
- data/lib/mongoid/contextual/memory.rb +5 -10
- data/lib/mongoid/contextual/mongo.rb +10 -27
- data/lib/mongoid/copyable.rb +6 -6
- data/lib/mongoid/criteria.rb +1 -2
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -3
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
- data/lib/mongoid/document.rb +6 -6
- data/lib/mongoid/errors.rb +3 -1
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +0 -1
- data/lib/mongoid/extensions/string.rb +1 -3
- data/lib/mongoid/factory.rb +4 -3
- data/lib/mongoid/fields.rb +1 -1
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/indexable.rb +8 -5
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable.rb +0 -3
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistable/creatable.rb +2 -4
- data/lib/mongoid/persistable/deletable.rb +9 -10
- data/lib/mongoid/persistable/destroyable.rb +5 -1
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -2
- data/lib/mongoid/persistence_context.rb +4 -9
- data/lib/mongoid/query_cache.rb +18 -65
- data/lib/mongoid/railtie.rb +0 -17
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +3 -3
- data/lib/mongoid/tasks/database.rb +2 -3
- data/lib/mongoid/threaded.rb +0 -74
- data/lib/mongoid/traversable.rb +2 -2
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -4
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/band.rb +0 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +1 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +613 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -93
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +11 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +1 -109
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- 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 -12
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/clients/factory_spec.rb +28 -52
- data/spec/mongoid/clients/options_spec.rb +65 -69
- data/spec/mongoid/config_spec.rb +24 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
- data/spec/mongoid/contextual/mongo_spec.rb +4 -112
- data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +6 -74
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +0 -81
- data/spec/mongoid/criteria_spec.rb +16 -19
- data/spec/mongoid/document_spec.rb +2 -56
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/extensions/regexp_spec.rb +0 -23
- data/spec/mongoid/extensions/string_spec.rb +7 -35
- data/spec/mongoid/factory_spec.rb +18 -11
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +2 -2
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +18 -8
- data/spec/mongoid/interceptable_spec.rb +21 -2
- data/spec/mongoid/matchable_spec.rb +1 -26
- data/spec/mongoid/persistable/deletable_spec.rb +0 -19
- data/spec/mongoid/persistable/destroyable_spec.rb +0 -19
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +3 -3
- data/spec/mongoid/persistable/settable_spec.rb +1 -35
- data/spec/mongoid/persistable/updatable_spec.rb +2 -2
- data/spec/mongoid/persistable_spec.rb +16 -16
- data/spec/mongoid/persistence_context_spec.rb +0 -14
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +18 -87
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +0 -13
- data/spec/mongoid/threaded_spec.rb +0 -68
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -83
- metadata +586 -611
- metadata.gz.sig +2 -5
- data/lib/mongoid/clients/sessions.rb +0 -113
- data/lib/mongoid/errors/invalid_session_use.rb +0 -24
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/railties/controller_runtime.rb +0 -86
- data/lib/mongoid/relations.rb +0 -148
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/spec/app/models/array_field.rb +0 -7
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/integration/document_spec.rb +0 -22
- data/spec/mongoid/clients/sessions_spec.rb +0 -334
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/constraints.rb +0 -101
- data/spec/support/macros.rb +0 -20
- data/spec/support/session_registry.rb +0 -50
- data/spec/support/spec_config.rb +0 -42
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
module Association
|
4
|
+
module Touchable
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
|
8
|
+
# Touch the document, in effect updating its updated_at timestamp and
|
9
|
+
# optionally the provided field to the current time. If any belongs_to
|
10
|
+
# relations exist with a touch option, they will be updated as well.
|
11
|
+
#
|
12
|
+
# @example Update the updated_at timestamp.
|
13
|
+
# document.touch
|
14
|
+
#
|
15
|
+
# @example Update the updated_at and provided timestamps.
|
16
|
+
# document.touch(:audited)
|
17
|
+
#
|
18
|
+
# @note This will not autobuild relations if those options are set.
|
19
|
+
#
|
20
|
+
# @param [ Symbol ] field The name of an additional field to update.
|
21
|
+
#
|
22
|
+
# @return [ true/false ] false if record is new_record otherwise true.
|
23
|
+
#
|
24
|
+
# @since 3.0.0
|
25
|
+
def touch(field = nil)
|
26
|
+
return false if _root.new_record?
|
27
|
+
current = Time.now
|
28
|
+
field = database_field_name(field)
|
29
|
+
write_attribute(:updated_at, current) if respond_to?("updated_at=")
|
30
|
+
write_attribute(field, current) if field
|
31
|
+
|
32
|
+
touches = touch_atomic_updates(field)
|
33
|
+
unless touches["$set"].blank?
|
34
|
+
selector = atomic_selector
|
35
|
+
_root.collection.find(selector).update_one(positionally(selector, touches))
|
36
|
+
end
|
37
|
+
run_callbacks(:touch)
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
extend self
|
43
|
+
|
44
|
+
# Add the association to the touchable relations if the touch option was
|
45
|
+
# provided.
|
46
|
+
#
|
47
|
+
# @example Add the touchable.
|
48
|
+
# Model.define_touchable!(assoc)
|
49
|
+
#
|
50
|
+
# @param [ Association ] association The association metadata.
|
51
|
+
#
|
52
|
+
# @return [ Class ] The model class.
|
53
|
+
#
|
54
|
+
# @since 3.0.0
|
55
|
+
def define_touchable!(association)
|
56
|
+
name = association.name
|
57
|
+
method_name = define_relation_touch_method(name, association)
|
58
|
+
association.inverse_class.tap do |klass|
|
59
|
+
klass.after_save method_name
|
60
|
+
klass.after_destroy method_name
|
61
|
+
klass.after_touch method_name
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Define the method that will get called for touching belongs_to
|
68
|
+
# relations.
|
69
|
+
#
|
70
|
+
# @api private
|
71
|
+
#
|
72
|
+
# @example Define the touch relation.
|
73
|
+
# Model.define_relation_touch_method(:band)
|
74
|
+
# Model.define_relation_touch_method(:band, :band_updated_at)
|
75
|
+
#
|
76
|
+
# @param [ Symbol ] name The name of the relation.
|
77
|
+
# @param [ Association ] association The association metadata.
|
78
|
+
#
|
79
|
+
# @since 3.1.0
|
80
|
+
#
|
81
|
+
# @return [ Symbol ] The method name.
|
82
|
+
def define_relation_touch_method(name, association)
|
83
|
+
association.relation_class.send(:include, InstanceMethods)
|
84
|
+
method_name = "touch_#{name}_after_create_or_destroy"
|
85
|
+
association.inverse_class.class_eval <<-TOUCH, __FILE__, __LINE__ + 1
|
86
|
+
def #{method_name}
|
87
|
+
without_autobuild do
|
88
|
+
relation = __send__(:#{name})
|
89
|
+
relation.touch #{":#{association.touch_field}" if association.touch_field} if relation
|
90
|
+
end
|
91
|
+
end
|
92
|
+
TOUCH
|
93
|
+
method_name.to_sym
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/mongoid/atomic.rb
CHANGED
@@ -36,7 +36,7 @@ module Mongoid
|
|
36
36
|
# @since 2.2.0
|
37
37
|
def add_atomic_pull(document)
|
38
38
|
document.flagged_for_destroy = true
|
39
|
-
(delayed_atomic_pulls[document.
|
39
|
+
(delayed_atomic_pulls[document.association_name.to_s] ||= []).push(document)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Add an atomic unset for the document.
|
@@ -51,7 +51,7 @@ module Mongoid
|
|
51
51
|
# @since 3.0.0
|
52
52
|
def add_atomic_unset(document)
|
53
53
|
document.flagged_for_destroy = true
|
54
|
-
(delayed_atomic_unsets[document.
|
54
|
+
(delayed_atomic_unsets[document.association_name.to_s] ||= []).push(document)
|
55
55
|
end
|
56
56
|
|
57
57
|
# Returns path of the attribute for modification
|
@@ -110,10 +110,10 @@ module Mongoid
|
|
110
110
|
# performed in a single operation. Conflicting modifications are
|
111
111
|
# detected by the 'haveConflictingMod' function in MongoDB.
|
112
112
|
# Examination of the code suggests that two modifications (a $set
|
113
|
-
# and a $
|
113
|
+
# and a $pushAll, for example) conflict if:
|
114
114
|
# (1) the key paths being modified are equal.
|
115
115
|
# (2) one key path is a prefix of the other.
|
116
|
-
# So a $set of 'addresses.0.street' will conflict with a $
|
116
|
+
# So a $set of 'addresses.0.street' will conflict with a $pushAll
|
117
117
|
# to 'addresses', and we will need to split our update into two
|
118
118
|
# pieces. We do not, however, attempt to match MongoDB's logic
|
119
119
|
# exactly. Instead, we assume that two updates conflict if the
|
@@ -189,7 +189,7 @@ module Mongoid
|
|
189
189
|
#
|
190
190
|
# @since 2.1.0
|
191
191
|
def atomic_paths
|
192
|
-
@atomic_paths ||=
|
192
|
+
@atomic_paths ||= _association ? _association.path(self) : Atomic::Paths::Root.new(self)
|
193
193
|
end
|
194
194
|
|
195
195
|
# Get all the attributes that need to be pulled.
|
@@ -218,7 +218,7 @@ module Mongoid
|
|
218
218
|
# @example Get the pushes.
|
219
219
|
# person.atomic_pushes
|
220
220
|
#
|
221
|
-
# @return [ Hash ] The
|
221
|
+
# @return [ Hash ] The $pushAll operations.
|
222
222
|
#
|
223
223
|
# @since 2.1.0
|
224
224
|
def atomic_pushes
|
@@ -68,7 +68,7 @@ module Mongoid
|
|
68
68
|
modifications.each_pair do |field, value|
|
69
69
|
push_fields[field] = field
|
70
70
|
mods = push_conflict?(field) ? conflicting_pushes : pushes
|
71
|
-
add_operation(mods, field,
|
71
|
+
add_operation(mods, field, Array.wrap(value))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -118,12 +118,8 @@ module Mongoid
|
|
118
118
|
# @since 2.2.0
|
119
119
|
def add_operation(mods, field, value)
|
120
120
|
if mods.has_key?(field)
|
121
|
-
|
122
|
-
|
123
|
-
mods[field].push(val)
|
124
|
-
end
|
125
|
-
elsif mods[field]['$each']
|
126
|
-
mods[field]['$each'].concat(value['$each'])
|
121
|
+
value.each do |val|
|
122
|
+
mods[field].push(val)
|
127
123
|
end
|
128
124
|
else
|
129
125
|
mods[field] = value
|
@@ -194,7 +190,7 @@ module Mongoid
|
|
194
190
|
#
|
195
191
|
# @since 2.2.0
|
196
192
|
def conflicting_pushes
|
197
|
-
conflicts["$
|
193
|
+
conflicts["$pushAll"] ||= {}
|
198
194
|
end
|
199
195
|
|
200
196
|
# Get the conflicting set modifications.
|
@@ -281,16 +277,16 @@ module Mongoid
|
|
281
277
|
self["$pull"] ||= {}
|
282
278
|
end
|
283
279
|
|
284
|
-
# Get the $
|
280
|
+
# Get the $pushAll operations or intialize a new one.
|
285
281
|
#
|
286
|
-
# @example Get the $
|
282
|
+
# @example Get the $pushAll operations.
|
287
283
|
# modifiers.pushes
|
288
284
|
#
|
289
|
-
# @return [ Hash ] The $
|
285
|
+
# @return [ Hash ] The $pushAll operations.
|
290
286
|
#
|
291
287
|
# @since 2.1.0
|
292
288
|
def pushes
|
293
|
-
self["$
|
289
|
+
self["$pushAll"] ||= {}
|
294
290
|
end
|
295
291
|
|
296
292
|
# Get the $set operations or intialize a new one.
|
@@ -35,7 +35,7 @@ module Mongoid
|
|
35
35
|
def position
|
36
36
|
pos = parent.atomic_position
|
37
37
|
locator = document.new_record? ? "" : ".#{document._index}"
|
38
|
-
"#{pos}#{"." unless pos.blank?}#{document.
|
38
|
+
"#{pos}#{"." unless pos.blank?}#{document._association.store_as}#{locator}"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -163,7 +163,8 @@ module Mongoid
|
|
163
163
|
#
|
164
164
|
# @since 1.0.0
|
165
165
|
def write_attribute(name, value)
|
166
|
-
|
166
|
+
access = database_field_name(name)
|
167
|
+
if attribute_writable?(access)
|
167
168
|
_assigning do
|
168
169
|
validate_attribute_value(access, value)
|
169
170
|
localized = fields[access].try(:localized?)
|
@@ -48,15 +48,15 @@ module Mongoid
|
|
48
48
|
args.each do |name|
|
49
49
|
meth = "#{name}_attributes="
|
50
50
|
self.nested_attributes["#{name}_attributes"] = meth
|
51
|
-
|
52
|
-
raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless
|
53
|
-
autosave_nested_attributes(
|
51
|
+
association = relations[name.to_s]
|
52
|
+
raise Errors::NestedAttributesMetadataNotFound.new(self, name) unless association
|
53
|
+
autosave_nested_attributes(association)
|
54
54
|
re_define_method(meth) do |attrs|
|
55
55
|
_assigning do
|
56
|
-
if
|
57
|
-
options = options.merge!(:class_name => self.send(
|
56
|
+
if association.polymorphic? and association.inverse_type
|
57
|
+
options = options.merge!(:class_name => self.send(association.inverse_type))
|
58
58
|
end
|
59
|
-
|
59
|
+
association.nested_builder(attrs, options).build(self)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -71,12 +71,12 @@ module Mongoid
|
|
71
71
|
# @example Add the autosave if appropriate.
|
72
72
|
# Person.autosave_nested_attributes(metadata)
|
73
73
|
#
|
74
|
-
# @param [
|
74
|
+
# @param [ Association ] association The existing association metadata.
|
75
75
|
#
|
76
76
|
# @since 3.1.4
|
77
|
-
def autosave_nested_attributes(
|
78
|
-
|
79
|
-
|
77
|
+
def autosave_nested_attributes(association)
|
78
|
+
if association.autosave?
|
79
|
+
Association::Referenced::AutoSave.define_autosave!(association)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -133,9 +133,9 @@ module Mongoid
|
|
133
133
|
# @since 2.0.0.rc.7
|
134
134
|
def process_relations
|
135
135
|
pending_relations.each_pair do |name, value|
|
136
|
-
|
136
|
+
association = relations[name]
|
137
137
|
if value.is_a?(Hash)
|
138
|
-
|
138
|
+
association.nested_builder(value, {}).build(self)
|
139
139
|
else
|
140
140
|
send("#{name}=", value)
|
141
141
|
end
|
@@ -22,17 +22,15 @@ module Mongoid
|
|
22
22
|
# readonly.
|
23
23
|
#
|
24
24
|
# @since 3.0.0
|
25
|
-
#
|
26
|
-
# @deprecated Use #as_writable_attribute! instead.
|
27
25
|
def attribute_writable?(name)
|
28
|
-
new_record? || !readonly_attributes.include?(
|
26
|
+
new_record? || (!readonly_attributes.include?(name) && _loaded?(name))
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
32
30
|
|
33
31
|
def as_writable_attribute!(name, value = :nil)
|
34
32
|
normalized_name = database_field_name(name)
|
35
|
-
if
|
33
|
+
if attribute_writable?(normalized_name)
|
36
34
|
yield(normalized_name)
|
37
35
|
else
|
38
36
|
raise Errors::ReadonlyAttribute.new(name, value)
|
data/lib/mongoid/clients.rb
CHANGED
@@ -3,14 +3,12 @@ require "mongoid/clients/factory"
|
|
3
3
|
require "mongoid/clients/validators"
|
4
4
|
require "mongoid/clients/storage_options"
|
5
5
|
require "mongoid/clients/options"
|
6
|
-
require "mongoid/clients/sessions"
|
7
6
|
|
8
7
|
module Mongoid
|
9
8
|
module Clients
|
10
9
|
extend ActiveSupport::Concern
|
11
10
|
include StorageOptions
|
12
11
|
include Options
|
13
|
-
include Sessions
|
14
12
|
|
15
13
|
class << self
|
16
14
|
|
data/lib/mongoid/composable.rb
CHANGED
@@ -43,7 +43,7 @@ module Mongoid
|
|
43
43
|
include Inspectable
|
44
44
|
include Matchable
|
45
45
|
include Persistable
|
46
|
-
include
|
46
|
+
include Association
|
47
47
|
include Reloadable
|
48
48
|
include Scopable
|
49
49
|
include Selectable
|
@@ -70,7 +70,7 @@ module Mongoid
|
|
70
70
|
Interceptable,
|
71
71
|
Matchable,
|
72
72
|
Persistable,
|
73
|
-
|
73
|
+
Association,
|
74
74
|
Reloadable,
|
75
75
|
Scopable,
|
76
76
|
Serializable,
|
@@ -83,8 +83,7 @@ module Mongoid
|
|
83
83
|
Traversable,
|
84
84
|
Validatable,
|
85
85
|
Equality,
|
86
|
-
|
87
|
-
Relations::Macros,
|
86
|
+
Association::Referenced::Syncable,
|
88
87
|
ActiveModel::Model,
|
89
88
|
ActiveModel::Validations
|
90
89
|
]
|
data/lib/mongoid/config.rb
CHANGED
@@ -27,6 +27,7 @@ module Mongoid
|
|
27
27
|
option :log_level, default: :info
|
28
28
|
option :belongs_to_required_by_default, default: true
|
29
29
|
option :app_name, default: nil
|
30
|
+
option :background_indexing, default: false
|
30
31
|
|
31
32
|
# Has Mongoid been configured? This is checking that at least a valid
|
32
33
|
# client config exists.
|
@@ -23,7 +23,7 @@ module Mongoid
|
|
23
23
|
#
|
24
24
|
# @since 3.0.0
|
25
25
|
def aggregates(field)
|
26
|
-
result = collection.find.aggregate(pipeline(field)
|
26
|
+
result = collection.find.aggregate(pipeline(field)).to_a
|
27
27
|
if result.empty?
|
28
28
|
{ "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
|
29
29
|
else
|
@@ -106,10 +106,10 @@ module Mongoid
|
|
106
106
|
view.update_many("$push" => collect_operations(pushes))
|
107
107
|
end
|
108
108
|
|
109
|
-
# Perform an atomic $
|
109
|
+
# Perform an atomic $pushAll operation on the matching documents.
|
110
110
|
#
|
111
111
|
# @example Push the values to the matching docs.
|
112
|
-
# context.
|
112
|
+
# context.push(members: [ "Alan", "Fletch" ])
|
113
113
|
#
|
114
114
|
# @param [ Hash ] pushes The operations.
|
115
115
|
#
|
@@ -117,10 +117,7 @@ module Mongoid
|
|
117
117
|
#
|
118
118
|
# @since 3.0.0
|
119
119
|
def push_all(pushes)
|
120
|
-
|
121
|
-
ops.merge!(field => {'$each' => elements})
|
122
|
-
end
|
123
|
-
view.update_many("$push" => push_each_updates)
|
120
|
+
view.update_many("$pushAll" => collect_operations(pushes))
|
124
121
|
end
|
125
122
|
|
126
123
|
# Perform an atomic $rename of fields on the matching documents.
|
@@ -165,13 +165,13 @@ module Mongoid
|
|
165
165
|
def raw
|
166
166
|
validate_out!
|
167
167
|
cmd = command
|
168
|
-
opts = { read: cmd.delete(:read) } if cmd[:read]
|
169
|
-
@map_reduce.database.command(cmd,
|
168
|
+
opts = { read: cmd.delete(:read).options } if cmd[:read]
|
169
|
+
@map_reduce.database.command(cmd, opts || {}).first
|
170
170
|
end
|
171
171
|
alias :results :raw
|
172
172
|
|
173
173
|
# Execute the map/reduce, returning the raw output.
|
174
|
-
# Useful when you don't care about map/reduce's
|
174
|
+
# Useful when you don't care about map/reduce's ouptut.
|
175
175
|
#
|
176
176
|
# @example Run the map reduce
|
177
177
|
# map_reduce.execute
|
@@ -249,10 +249,6 @@ module Mongoid
|
|
249
249
|
def validate_out!
|
250
250
|
raise Errors::NoMapReduceOutput.new({}) unless @map_reduce.out
|
251
251
|
end
|
252
|
-
|
253
|
-
def _session
|
254
|
-
criteria.send(:_session)
|
255
|
-
end
|
256
252
|
end
|
257
253
|
end
|
258
254
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "mongoid/contextual/aggregable/memory"
|
3
|
-
require "mongoid/
|
3
|
+
require "mongoid/association/eager_loadable"
|
4
4
|
|
5
5
|
module Mongoid
|
6
6
|
module Contextual
|
7
7
|
class Memory
|
8
8
|
include Enumerable
|
9
9
|
include Aggregable::Memory
|
10
|
-
include
|
10
|
+
include Association::EagerLoadable
|
11
11
|
include Queryable
|
12
12
|
include Positional
|
13
13
|
|
@@ -48,8 +48,7 @@ module Mongoid
|
|
48
48
|
end
|
49
49
|
unless removed.empty?
|
50
50
|
collection.find(selector).update_one(
|
51
|
-
positionally(selector, "$pullAll" => { path => removed })
|
52
|
-
session: _session
|
51
|
+
positionally(selector, "$pullAll" => { path => removed })
|
53
52
|
)
|
54
53
|
end
|
55
54
|
deleted
|
@@ -130,7 +129,7 @@ module Mongoid
|
|
130
129
|
# @return [ Document ] The first document.
|
131
130
|
#
|
132
131
|
# @since 3.0.0
|
133
|
-
def first
|
132
|
+
def first(*args)
|
134
133
|
eager_load([documents.first]).first
|
135
134
|
end
|
136
135
|
alias :one :first
|
@@ -304,7 +303,7 @@ module Mongoid
|
|
304
303
|
updates["$set"].merge!(doc.atomic_updates["$set"] || {})
|
305
304
|
doc.move_changes
|
306
305
|
end
|
307
|
-
collection.find(selector).update_one(updates
|
306
|
+
collection.find(selector).update_one(updates) unless updates["$set"].empty?
|
308
307
|
end
|
309
308
|
|
310
309
|
# Get the limiting value.
|
@@ -445,10 +444,6 @@ module Mongoid
|
|
445
444
|
doc._parent.remove_child(doc)
|
446
445
|
doc.destroyed = true
|
447
446
|
end
|
448
|
-
|
449
|
-
def _session
|
450
|
-
@criteria.send(:_session)
|
451
|
-
end
|
452
447
|
end
|
453
448
|
end
|
454
449
|
end
|