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
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid
|
3
|
-
module
|
3
|
+
module Association
|
4
4
|
module Embedded
|
5
5
|
|
6
6
|
# Contains behaviour for executing operations in batch on embedded
|
@@ -8,7 +8,7 @@ module Mongoid
|
|
8
8
|
module Batchable
|
9
9
|
include Positional
|
10
10
|
|
11
|
-
# Insert new documents as a batch push ($
|
11
|
+
# Insert new documents as a batch push ($pushAll). This ensures that
|
12
12
|
# all callbacks are run at the appropriate time and only 1 request is
|
13
13
|
# made to the database.
|
14
14
|
#
|
@@ -21,7 +21,7 @@ module Mongoid
|
|
21
21
|
#
|
22
22
|
# @since 3.0.0
|
23
23
|
def batch_insert(docs)
|
24
|
-
|
24
|
+
execute_batch_insert(docs, "$pushAll")
|
25
25
|
end
|
26
26
|
|
27
27
|
# Clear all of the docs out of the relation in a single swipe.
|
@@ -38,8 +38,7 @@ module Mongoid
|
|
38
38
|
pre_process_batch_remove(docs, :delete)
|
39
39
|
unless docs.empty?
|
40
40
|
collection.find(selector).update_one(
|
41
|
-
|
42
|
-
session: _session
|
41
|
+
positionally(selector, "$unset" => { path => true })
|
43
42
|
)
|
44
43
|
post_process_batch_remove(docs, :delete)
|
45
44
|
end
|
@@ -59,8 +58,7 @@ module Mongoid
|
|
59
58
|
removals = pre_process_batch_remove(docs, method)
|
60
59
|
if !docs.empty?
|
61
60
|
collection.find(selector).update_one(
|
62
|
-
|
63
|
-
session: _session
|
61
|
+
positionally(selector, "$pullAll" => { path => removals })
|
64
62
|
)
|
65
63
|
post_process_batch_remove(docs, method)
|
66
64
|
end
|
@@ -80,18 +78,18 @@ module Mongoid
|
|
80
78
|
def batch_replace(docs)
|
81
79
|
if docs.blank?
|
82
80
|
if _assigning? && !empty?
|
83
|
-
|
84
|
-
target_duplicate =
|
81
|
+
_base.add_atomic_unset(first)
|
82
|
+
target_duplicate = _target.dup
|
85
83
|
pre_process_batch_remove(target_duplicate, :delete)
|
86
84
|
post_process_batch_remove(target_duplicate, :delete)
|
87
85
|
else
|
88
|
-
batch_remove(
|
86
|
+
batch_remove(_target.dup)
|
89
87
|
end
|
90
|
-
elsif
|
91
|
-
|
88
|
+
elsif _target != docs
|
89
|
+
_base.delayed_atomic_sets.clear unless _assigning?
|
92
90
|
docs = normalize_docs(docs).compact
|
93
|
-
|
94
|
-
inserts =
|
91
|
+
_target.clear and _unscoped.clear
|
92
|
+
inserts = execute_batch_insert(docs, "$set")
|
95
93
|
add_atomic_sets(inserts)
|
96
94
|
end
|
97
95
|
end
|
@@ -110,64 +108,40 @@ module Mongoid
|
|
110
108
|
# @since 3.0.0
|
111
109
|
def add_atomic_sets(sets)
|
112
110
|
if _assigning?
|
113
|
-
|
114
|
-
|
111
|
+
_base.delayed_atomic_sets[path].try(:clear)
|
112
|
+
_base.collect_children.each do |child|
|
115
113
|
child.delayed_atomic_sets.clear
|
116
114
|
end
|
117
|
-
|
115
|
+
_base.delayed_atomic_sets[path] = sets
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
121
|
-
# Perform a batch persist of the provided documents with
|
119
|
+
# Perform a batch persist of the provided documents with the supplied
|
120
|
+
# operation.
|
122
121
|
#
|
123
122
|
# @api private
|
124
123
|
#
|
125
|
-
|
126
|
-
# batchable.
|
124
|
+
# @example Perform a batch operation.
|
125
|
+
# batchable.execute_batch(docs, "$set")
|
127
126
|
#
|
128
127
|
# @param [ Array<Document> ] docs The docs to persist.
|
128
|
+
# @param [ String ] operation The atomic operation.
|
129
129
|
#
|
130
130
|
# @return [ Array<Hash> ] The inserts.
|
131
131
|
#
|
132
|
-
# @since
|
133
|
-
def
|
132
|
+
# @since 3.0.0
|
133
|
+
def execute_batch_insert(docs, operation)
|
134
134
|
self.inserts_valid = true
|
135
135
|
inserts = pre_process_batch_insert(docs)
|
136
136
|
if insertable?
|
137
137
|
collection.find(selector).update_one(
|
138
|
-
positionally(selector,
|
139
|
-
session: _session
|
138
|
+
positionally(selector, operation => { path => inserts })
|
140
139
|
)
|
141
140
|
post_process_batch_insert(docs)
|
142
141
|
end
|
143
142
|
inserts
|
144
143
|
end
|
145
144
|
|
146
|
-
# Perform a batch persist of the provided documents with $push and $each.
|
147
|
-
#
|
148
|
-
# @api private
|
149
|
-
#
|
150
|
-
# @example Perform a batch push.
|
151
|
-
# batchable.execute_batch_push(docs)
|
152
|
-
#
|
153
|
-
# @param [ Array<Document> ] docs The docs to persist.
|
154
|
-
#
|
155
|
-
# @return [ Array<Hash> ] The inserts.
|
156
|
-
#
|
157
|
-
# @since 7.0.0
|
158
|
-
def execute_batch_push(docs)
|
159
|
-
self.inserts_valid = true
|
160
|
-
pushes = pre_process_batch_insert(docs)
|
161
|
-
if insertable?
|
162
|
-
collection.find(selector).update_one(
|
163
|
-
positionally(selector, '$push' => { path => { '$each' => pushes } }),
|
164
|
-
session: _session
|
165
|
-
)
|
166
|
-
post_process_batch_insert(docs)
|
167
|
-
end
|
168
|
-
pushes
|
169
|
-
end
|
170
|
-
|
171
145
|
# Are we in a state to be able to batch insert?
|
172
146
|
#
|
173
147
|
# @api private
|
@@ -228,7 +202,7 @@ module Mongoid
|
|
228
202
|
def normalize_docs(docs)
|
229
203
|
if docs.first.is_a?(::Hash)
|
230
204
|
docs.map do |doc|
|
231
|
-
attributes = {
|
205
|
+
attributes = { _association: _association, _parent: _base }
|
232
206
|
attributes.merge!(doc)
|
233
207
|
Factory.build(klass, attributes)
|
234
208
|
end
|
@@ -278,7 +252,7 @@ module Mongoid
|
|
278
252
|
#
|
279
253
|
# @since 3.0.0
|
280
254
|
def selector
|
281
|
-
@selector ||=
|
255
|
+
@selector ||= _base.atomic_selector
|
282
256
|
end
|
283
257
|
|
284
258
|
# Pre processes the batch insert for the provided documents.
|
@@ -327,10 +301,10 @@ module Mongoid
|
|
327
301
|
self.path = doc.atomic_path unless path
|
328
302
|
execute_callback :before_remove, doc
|
329
303
|
unless _assigning?
|
330
|
-
doc.
|
304
|
+
doc.apply_delete_dependencies!
|
331
305
|
doc.run_before_callbacks(:destroy) if method == :destroy
|
332
306
|
end
|
333
|
-
|
307
|
+
_target.delete_one(doc)
|
334
308
|
_unscoped.delete_one(doc)
|
335
309
|
unbind_one(doc)
|
336
310
|
execute_callback :after_remove, doc
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
module Association
|
4
|
+
module Embedded
|
5
|
+
|
6
|
+
# This module provides convenience macros for using cyclic embedded
|
7
|
+
# relations.
|
8
|
+
module Cyclic
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
class_attribute :cyclic
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
# Create a cyclic embedded relation that creates a tree hierarchy for
|
18
|
+
# the document and many embedded child documents.
|
19
|
+
#
|
20
|
+
# @example Set up a recursive embeds many.
|
21
|
+
#
|
22
|
+
# class Role
|
23
|
+
# include Mongoid::Document
|
24
|
+
# recursively_embeds_many
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @example The previous example is a shorcut for this.
|
28
|
+
#
|
29
|
+
# class Role
|
30
|
+
# include Mongoid::Document
|
31
|
+
# embeds_many :child_roles, :class_name => "Role", :cyclic => true
|
32
|
+
# embedded_in :parent_role, :class_name => "Role", :cyclic => true
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# This provides the default nomenclature for accessing a parent document
|
36
|
+
# or its children.
|
37
|
+
#
|
38
|
+
# @since 2.0.0.rc.1
|
39
|
+
def recursively_embeds_many(options = {})
|
40
|
+
embeds_many(
|
41
|
+
cyclic_child_name,
|
42
|
+
options.merge(class_name: self.name, cyclic: true)
|
43
|
+
)
|
44
|
+
embedded_in cyclic_parent_name, class_name: self.name, cyclic: true
|
45
|
+
end
|
46
|
+
|
47
|
+
# Create a cyclic embedded relation that creates a single self
|
48
|
+
# referencing relationship for a parent and a single child.
|
49
|
+
#
|
50
|
+
# @example Set up a recursive embeds one.
|
51
|
+
#
|
52
|
+
# class Role
|
53
|
+
# include Mongoid::Document
|
54
|
+
# recursively_embeds_one
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# @example The previous example is a shorcut for this.
|
58
|
+
#
|
59
|
+
# class Role
|
60
|
+
# include Mongoid::Document
|
61
|
+
# embeds_one :child_role, :class_name => "Role", :cyclic => true
|
62
|
+
# embedded_in :parent_role, :class_name => "Role", :cyclic => true
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# This provides the default nomenclature for accessing a parent document
|
66
|
+
# or its children.
|
67
|
+
#
|
68
|
+
# @since 2.0.0.rc.1
|
69
|
+
def recursively_embeds_one(options = {})
|
70
|
+
embeds_one(
|
71
|
+
cyclic_child_name(false),
|
72
|
+
options.merge(class_name: self.name, cyclic: true)
|
73
|
+
)
|
74
|
+
embedded_in cyclic_parent_name, class_name: self.name, cyclic: true
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# Determines the parent name given the class.
|
80
|
+
#
|
81
|
+
# @example Determine the parent name.
|
82
|
+
# Role.cyclic_parent_name
|
83
|
+
#
|
84
|
+
# @return [ String ] "parent_" plus the class name underscored.
|
85
|
+
#
|
86
|
+
# @since 2.0.0.rc.1
|
87
|
+
def cyclic_parent_name
|
88
|
+
("parent_" << self.name.demodulize.underscore.singularize).to_sym
|
89
|
+
end
|
90
|
+
|
91
|
+
# Determines the child name given the class.
|
92
|
+
#
|
93
|
+
# @example Determine the child name.
|
94
|
+
# Role.cyclic_child_name
|
95
|
+
#
|
96
|
+
# @param [ true, false ] many Is the a many relation?
|
97
|
+
#
|
98
|
+
# @return [ String ] "child_" plus the class name underscored in
|
99
|
+
# singular or plural form.
|
100
|
+
#
|
101
|
+
# @since 2.0.0.rc.1
|
102
|
+
def cyclic_child_name(many = true)
|
103
|
+
("child_" << self.name.demodulize.underscore.send(many ? :pluralize : :singularize)).to_sym
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'mongoid/association/embedded/embedded_in/binding'
|
2
|
+
require 'mongoid/association/embedded/embedded_in/buildable'
|
3
|
+
require 'mongoid/association/embedded/embedded_in/proxy'
|
4
|
+
|
5
|
+
module Mongoid
|
6
|
+
module Association
|
7
|
+
module Embedded
|
8
|
+
|
9
|
+
# The EmbeddedIn type association.
|
10
|
+
#
|
11
|
+
# @since 7.0
|
12
|
+
class EmbeddedIn
|
13
|
+
include Relatable
|
14
|
+
include Buildable
|
15
|
+
|
16
|
+
# The options available for this type of association, in addition to the
|
17
|
+
# common ones.
|
18
|
+
#
|
19
|
+
# @return [ Array<Symbol> ] The extra valid options.
|
20
|
+
#
|
21
|
+
# @since 7.0
|
22
|
+
ASSOCIATION_OPTIONS = [
|
23
|
+
:autobuild,
|
24
|
+
:cyclic,
|
25
|
+
:polymorphic,
|
26
|
+
:touch
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
# The complete list of valid options for this association, including
|
30
|
+
# the shared ones.
|
31
|
+
#
|
32
|
+
# @return [ Array<Symbol> ] The valid options.
|
33
|
+
#
|
34
|
+
# @since 7.0
|
35
|
+
VALID_OPTIONS = (ASSOCIATION_OPTIONS + SHARED_OPTIONS).freeze
|
36
|
+
|
37
|
+
# Setup the instance methods, fields, etc. on the association owning class.
|
38
|
+
#
|
39
|
+
# @return [ self ]
|
40
|
+
#
|
41
|
+
# @since 7.0
|
42
|
+
def setup!
|
43
|
+
setup_instance_methods!
|
44
|
+
@owner_class.embedded = true
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Is this association type embedded?
|
49
|
+
#
|
50
|
+
# @return [ true ] Always true.
|
51
|
+
#
|
52
|
+
# @since 7.0
|
53
|
+
def embedded?; true; end
|
54
|
+
|
55
|
+
# The primary key
|
56
|
+
#
|
57
|
+
# @return [ nil ] Not relevant for this relation
|
58
|
+
def primary_key; end
|
59
|
+
|
60
|
+
# Does this association type store the foreign key?
|
61
|
+
#
|
62
|
+
# @return [ false ] Always false.
|
63
|
+
#
|
64
|
+
# @since 7.0
|
65
|
+
def stores_foreign_key?; false; end
|
66
|
+
|
67
|
+
# The default for validating the association object.
|
68
|
+
#
|
69
|
+
# @return [ false ] Always false.
|
70
|
+
#
|
71
|
+
# @since 7.0
|
72
|
+
def validation_default; false; end
|
73
|
+
|
74
|
+
# The key that is used to get the attributes for the associated object.
|
75
|
+
#
|
76
|
+
# @return [ String ] The name of the relation.
|
77
|
+
#
|
78
|
+
# @since 7.0
|
79
|
+
def key
|
80
|
+
@key ||= name.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get the relation proxy class for this association type.
|
84
|
+
#
|
85
|
+
# @return [ Association::Embedded::EmbeddedIn::Proxy ] The proxy class.
|
86
|
+
#
|
87
|
+
# @since 7.0
|
88
|
+
def relation
|
89
|
+
Proxy
|
90
|
+
end
|
91
|
+
|
92
|
+
# Is this association polymorphic?
|
93
|
+
#
|
94
|
+
# @return [ true, false ] Whether this association is polymorphic.
|
95
|
+
#
|
96
|
+
# @since 7.0
|
97
|
+
def polymorphic?
|
98
|
+
!!@options[:polymorphic]
|
99
|
+
end
|
100
|
+
|
101
|
+
# The nested builder object.
|
102
|
+
#
|
103
|
+
# @param [ Hash ] attributes The attributes to use to build the association object.
|
104
|
+
# @param [ Hash ] options The options for the association.
|
105
|
+
#
|
106
|
+
# @return [ Association::Nested::One ] The Nested Builder object.
|
107
|
+
#
|
108
|
+
# @since 7.0
|
109
|
+
def nested_builder(attributes, options)
|
110
|
+
Nested::One.new(self, attributes, options)
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def setup_instance_methods!
|
116
|
+
define_getter!
|
117
|
+
define_setter!
|
118
|
+
define_existence_check!
|
119
|
+
define_builder!
|
120
|
+
define_creator!
|
121
|
+
define_counter_cache_callbacks!
|
122
|
+
define_touchable!
|
123
|
+
end
|
124
|
+
|
125
|
+
def relation_complements
|
126
|
+
@relation_complements ||= [ Embedded::EmbedsMany,
|
127
|
+
Embedded::EmbedsOne ].freeze
|
128
|
+
end
|
129
|
+
|
130
|
+
def polymorphic_inverses(other = nil)
|
131
|
+
if other
|
132
|
+
matches = other.relations.values.select do |rel|
|
133
|
+
relation_complements.include?(rel.class) &&
|
134
|
+
rel.as == name &&
|
135
|
+
rel.relation_class_name == inverse_class_name
|
136
|
+
end
|
137
|
+
matches.collect { |m| m.name }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def determine_inverses(other)
|
142
|
+
matches = (other || relation_class).relations.values.select do |rel|
|
143
|
+
relation_complements.include?(rel.class) &&
|
144
|
+
rel.relation_class_name == inverse_class_name
|
145
|
+
end
|
146
|
+
if matches.size > 1
|
147
|
+
raise Errors::AmbiguousRelationship.new(relation_class, @owner_class, name, matches)
|
148
|
+
end
|
149
|
+
matches.collect { |m| m.name } unless matches.blank?
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Association
|
3
|
+
module Embedded
|
4
|
+
class EmbeddedIn
|
5
|
+
|
6
|
+
# The Binding object for embedded_in associations.
|
7
|
+
#
|
8
|
+
# @since 7.0
|
9
|
+
class Binding
|
10
|
+
include Bindable
|
11
|
+
|
12
|
+
# Binds the base object to the inverse of the relation. This is so we
|
13
|
+
# are referenced to the actual objects themselves on both sides.
|
14
|
+
#
|
15
|
+
# This case sets the association metadata on the inverse object as well as the
|
16
|
+
# document itself.
|
17
|
+
#
|
18
|
+
# @example Bind the documents.
|
19
|
+
# name.person.bind(:continue => true)
|
20
|
+
# name.person = Person.new
|
21
|
+
#
|
22
|
+
# @since 2.0.0.rc.1
|
23
|
+
def bind_one
|
24
|
+
_base._association = _association.inverse_association(_target) unless _base._association
|
25
|
+
_base.parentize(_target)
|
26
|
+
binding do
|
27
|
+
if _base.embedded_many?
|
28
|
+
_target.do_or_do_not(_association.inverse(_target)).push(_base)
|
29
|
+
else
|
30
|
+
_target.do_or_do_not(_association.inverse_setter(_target), _base)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Unbinds the base object and the inverse, caused by setting the
|
36
|
+
# reference to nil.
|
37
|
+
#
|
38
|
+
# @example Unbind the document.
|
39
|
+
# name.person.unbind(:continue => true)
|
40
|
+
# name.person = nil
|
41
|
+
#
|
42
|
+
# @since 2.0.0.rc.1
|
43
|
+
def unbind_one
|
44
|
+
binding do
|
45
|
+
if _base.embedded_many?
|
46
|
+
_target.do_or_do_not(_association.inverse(_target)).delete(_base)
|
47
|
+
else
|
48
|
+
_target.do_or_do_not(_association.inverse_setter(_target), nil)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|