mongoid 6.4.2 → 7.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/config/locales/en.yml +17 -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 +137 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +19 -19
- data/lib/mongoid/association/embedded/cyclic.rb +109 -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/embedded_in.rb +154 -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 +552 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -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/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +19 -49
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- 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/association/nested.rb +15 -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/auto_save.rb +79 -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/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +162 -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 +312 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -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 +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -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/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +509 -0
- data/lib/mongoid/{relations.rb → association.rb} +57 -56
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +22 -11
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +21 -3
- data/lib/mongoid/contextual/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +7 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +37 -7
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +15 -6
- 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/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +5 -2
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -0
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- 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/fields.rb +3 -3
- data/lib/mongoid/indexable.rb +4 -1
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable/eq.rb +22 -0
- data/lib/mongoid/matchable/ne.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -1
- data/lib/mongoid/persistable/deletable.rb +7 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +20 -5
- data/lib/mongoid/query_cache.rb +8 -4
- data/lib/mongoid/railtie.rb +17 -0
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/threaded.rb +36 -0
- data/lib/mongoid/touchable.rb +102 -0
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/minim.rb +7 -0
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/store_as_dup_test3.rb +7 -0
- data/spec/app/models/store_as_dup_test4.rb +7 -0
- data/spec/app/models/updatable.rb +7 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +13 -3
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/lite_spec_helper.rb +56 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +40 -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 +866 -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/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} +124 -182
- 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 -73
- 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 +66 -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} +33 -14
- 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 +2006 -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} +26 -7
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +56 -0
- 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_models.rb +26 -0
- 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} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_models.rb +37 -0
- 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_models.rb +48 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1350 -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_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +24 -18
- data/spec/mongoid/clients/options_spec.rb +58 -44
- data/spec/mongoid/clients/sessions_spec.rb +1 -1
- data/spec/mongoid/clients/transactions_spec.rb +369 -0
- data/spec/mongoid/clients_spec.rb +68 -8
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +33 -5
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -0
- 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/extensions/string_spec.rb +43 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +42 -3
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +33 -18
- data/spec/mongoid/document_spec.rb +83 -4
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- 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 +23 -0
- data/spec/mongoid/factory_spec.rb +19 -1
- 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 +22 -1
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable/eq_spec.rb +48 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +95 -10
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/persistence_context_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +61 -22
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/{relations/touchable_spec.rb → touchable_spec.rb} +40 -1
- 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/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +51 -25
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/spec_config.rb +39 -0
- metadata +602 -582
- checksums.yaml.gz.sig +0 -2
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- 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/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- 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/builders.rb +0 -106
- 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/cascading.rb +0 -56
- 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/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- 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/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.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
@@ -1,26 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid
|
3
|
-
module
|
3
|
+
module Association
|
4
4
|
|
5
5
|
# Used for converting foreign key values to the correct type based on the
|
6
6
|
# types of ids that the document stores.
|
7
7
|
#
|
8
|
-
|
9
|
-
# getter, and foreign_key was already taken there.
|
10
|
-
class Constraint
|
11
|
-
attr_reader :metadata
|
12
|
-
|
13
|
-
# Create the new constraint with the metadata.
|
14
|
-
#
|
15
|
-
# @example Instantiate the constraint.
|
16
|
-
# Constraint.new(metdata)
|
17
|
-
#
|
18
|
-
# @param [ Metadata ] metadata The metadata of the relation.
|
19
|
-
#
|
20
|
-
# @since 2.0.0.rc.7
|
21
|
-
def initialize(metadata)
|
22
|
-
@metadata = metadata
|
23
|
-
end
|
8
|
+
module Constrainable
|
24
9
|
|
25
10
|
# Convert the supplied object to the appropriate type to set as the
|
26
11
|
# foreign key for a relation.
|
@@ -33,10 +18,10 @@ module Mongoid
|
|
33
18
|
# @return [ Object ] The object cast to the correct type.
|
34
19
|
#
|
35
20
|
# @since 2.0.0.rc.7
|
36
|
-
def
|
37
|
-
return convert_polymorphic(object) if
|
38
|
-
|
39
|
-
if
|
21
|
+
def convert_to_foreign_key(object)
|
22
|
+
return convert_polymorphic(object) if polymorphic?
|
23
|
+
field = relation_class.fields["_id"]
|
24
|
+
if relation_class.using_object_ids?
|
40
25
|
BSON::ObjectId.mongoize(object)
|
41
26
|
elsif object.is_a?(::Array)
|
42
27
|
object.map!{ |obj| field.mongoize(obj) }
|
@@ -48,7 +33,11 @@ module Mongoid
|
|
48
33
|
private
|
49
34
|
|
50
35
|
def convert_polymorphic(object)
|
51
|
-
object.
|
36
|
+
if object.is_a?(Mongoid::Document)
|
37
|
+
object.id
|
38
|
+
else
|
39
|
+
BSON::ObjectId.mongoize(object)
|
40
|
+
end
|
52
41
|
end
|
53
42
|
end
|
54
43
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Association
|
3
|
+
|
4
|
+
# This module defines the behaviour for setting up cascading deletes and
|
5
|
+
# nullifies for relations, and how to delegate to the appropriate strategy.
|
6
|
+
module Depending
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :dependents
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
class_attribute :dependents_owner
|
14
|
+
|
15
|
+
self.dependents = []
|
16
|
+
self.dependents_owner = self
|
17
|
+
end
|
18
|
+
|
19
|
+
class_methods do
|
20
|
+
# @api private
|
21
|
+
def _all_dependents
|
22
|
+
superclass_dependents = superclass.respond_to?(:_all_dependents) ? superclass._all_dependents : []
|
23
|
+
dependents + superclass_dependents.reject do |new_dep|
|
24
|
+
dependents.any? do |old_dep| old_dep.name == new_dep.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# The valid dependent strategies.
|
31
|
+
#
|
32
|
+
# @since 7.0
|
33
|
+
STRATEGIES = [
|
34
|
+
:delete_all,
|
35
|
+
:destroy,
|
36
|
+
:nullify,
|
37
|
+
:restrict_with_exception,
|
38
|
+
:restrict_with_error
|
39
|
+
]
|
40
|
+
|
41
|
+
# The error message when a strategy cannot delete objects because there are associated objects.
|
42
|
+
#
|
43
|
+
# @since 7.0
|
44
|
+
RESTRICT_ERROR_MSG = 'Cannot delete record because associated objects exist.'.freeze
|
45
|
+
|
46
|
+
# Attempt to add the cascading information for the document to know how
|
47
|
+
# to handle associated documents on a removal.
|
48
|
+
#
|
49
|
+
# @example Set up cascading information
|
50
|
+
# Mongoid::Association::Depending.define_dependency!(association)
|
51
|
+
#
|
52
|
+
# @param [ Association ] association The association metadata.
|
53
|
+
#
|
54
|
+
# @return [ Class ] The class of the document.
|
55
|
+
#
|
56
|
+
# @since 2.0.0.rc.1
|
57
|
+
def self.define_dependency!(association)
|
58
|
+
validate!(association)
|
59
|
+
association.inverse_class.tap do |klass|
|
60
|
+
if klass.dependents_owner != klass
|
61
|
+
klass.dependents = []
|
62
|
+
klass.dependents_owner = klass
|
63
|
+
end
|
64
|
+
|
65
|
+
if association.dependent && !klass.dependents.include?(association)
|
66
|
+
klass.dependents.push(association)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.validate!(association)
|
72
|
+
unless STRATEGIES.include?(association.dependent)
|
73
|
+
raise Errors::InvalidDependentStrategy.new(association,
|
74
|
+
association.dependent,
|
75
|
+
STRATEGIES)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Perform all cascading deletes, destroys, or nullifies. Will delegate to
|
80
|
+
# the appropriate strategy to perform the operation.
|
81
|
+
#
|
82
|
+
# @example Execute cascades.
|
83
|
+
# document.apply_delete_dependencies!
|
84
|
+
#
|
85
|
+
# @since 2.0.0.rc.1
|
86
|
+
def apply_delete_dependencies!
|
87
|
+
self.class._all_dependents.each do |association|
|
88
|
+
if association.try(:dependent)
|
89
|
+
send("_dependent_#{association.dependent}!", association)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def _dependent_delete_all!(association)
|
97
|
+
if relation = send(association.name)
|
98
|
+
if relation.respond_to?(:dependents) && relation.dependents.blank?
|
99
|
+
relation.clear
|
100
|
+
else
|
101
|
+
::Array.wrap(send(association.name)).each { |rel| rel.delete }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def _dependent_destroy!(association)
|
107
|
+
if relation = send(association.name)
|
108
|
+
if relation.is_a?(Enumerable)
|
109
|
+
relation.entries
|
110
|
+
relation.each { |doc| doc.destroy }
|
111
|
+
else
|
112
|
+
relation.destroy
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def _dependent_nullify!(association)
|
118
|
+
if relation = send(association.name)
|
119
|
+
relation.nullify
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def _dependent_restrict_with_exception!(association)
|
124
|
+
if (relation = send(association.name)) && !relation.blank?
|
125
|
+
raise Errors::DeleteRestriction.new(relation, association.name)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def _dependent_restrict_with_error!(association)
|
130
|
+
if (relation = send(association.name)) && !relation.blank?
|
131
|
+
errors.add(association.name, RESTRICT_ERROR_MSG)
|
132
|
+
throw(:abort, false)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "mongoid/
|
3
|
-
require "mongoid/relations/eager/belongs_to"
|
4
|
-
require "mongoid/relations/eager/has_one"
|
5
|
-
require "mongoid/relations/eager/has_many"
|
6
|
-
require "mongoid/relations/eager/has_and_belongs_to_many"
|
2
|
+
require "mongoid/association/referenced/eager"
|
7
3
|
|
8
4
|
module Mongoid
|
9
|
-
module
|
10
|
-
|
5
|
+
module Association
|
6
|
+
|
7
|
+
# This module defines the eager loading behavior for criteria.
|
8
|
+
#
|
9
|
+
# @since 7.0
|
10
|
+
module EagerLoadable
|
11
11
|
|
12
12
|
def eager_loadable?
|
13
13
|
!criteria.inclusions.empty?
|
@@ -23,11 +23,11 @@ module Mongoid
|
|
23
23
|
|
24
24
|
def preload(relations, docs)
|
25
25
|
relations.group_by(&:inverse_class_name)
|
26
|
-
|
27
|
-
|
26
|
+
.values
|
27
|
+
.each do |associations|
|
28
28
|
associations.group_by(&:relation)
|
29
|
-
|
30
|
-
relation.
|
29
|
+
.each do |relation, association|
|
30
|
+
relation.eager_loader(association, docs).run
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -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
|
@@ -38,8 +38,8 @@ module Mongoid
|
|
38
38
|
pre_process_batch_remove(docs, :delete)
|
39
39
|
unless docs.empty?
|
40
40
|
collection.find(selector).update_one(
|
41
|
-
|
42
|
-
|
41
|
+
positionally(selector, "$unset" => { path => true }),
|
42
|
+
session: _session
|
43
43
|
)
|
44
44
|
post_process_batch_remove(docs, :delete)
|
45
45
|
end
|
@@ -59,8 +59,8 @@ module Mongoid
|
|
59
59
|
removals = pre_process_batch_remove(docs, method)
|
60
60
|
if !docs.empty?
|
61
61
|
collection.find(selector).update_one(
|
62
|
-
|
63
|
-
|
62
|
+
positionally(selector, "$pullAll" => { path => removals }),
|
63
|
+
session: _session
|
64
64
|
)
|
65
65
|
post_process_batch_remove(docs, method)
|
66
66
|
end
|
@@ -80,17 +80,17 @@ module Mongoid
|
|
80
80
|
def batch_replace(docs)
|
81
81
|
if docs.blank?
|
82
82
|
if _assigning? && !empty?
|
83
|
-
|
84
|
-
target_duplicate =
|
83
|
+
_base.add_atomic_unset(first)
|
84
|
+
target_duplicate = _target.dup
|
85
85
|
pre_process_batch_remove(target_duplicate, :delete)
|
86
86
|
post_process_batch_remove(target_duplicate, :delete)
|
87
87
|
else
|
88
|
-
batch_remove(
|
88
|
+
batch_remove(_target.dup)
|
89
89
|
end
|
90
|
-
elsif
|
91
|
-
|
90
|
+
elsif _target != docs
|
91
|
+
_base.delayed_atomic_sets.clear unless _assigning?
|
92
92
|
docs = normalize_docs(docs).compact
|
93
|
-
|
93
|
+
_target.clear and _unscoped.clear
|
94
94
|
inserts = execute_batch_set(docs)
|
95
95
|
add_atomic_sets(inserts)
|
96
96
|
end
|
@@ -110,11 +110,11 @@ module Mongoid
|
|
110
110
|
# @since 3.0.0
|
111
111
|
def add_atomic_sets(sets)
|
112
112
|
if _assigning?
|
113
|
-
|
114
|
-
|
113
|
+
_base.delayed_atomic_sets[path].try(:clear)
|
114
|
+
_base.collect_children.each do |child|
|
115
115
|
child.delayed_atomic_sets.clear
|
116
116
|
end
|
117
|
-
|
117
|
+
_base.delayed_atomic_sets[path] = sets
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -122,7 +122,7 @@ module Mongoid
|
|
122
122
|
#
|
123
123
|
# @api private
|
124
124
|
#
|
125
|
-
|
125
|
+
# @example Perform a batch $set.
|
126
126
|
# batchable.execute_batch_set(docs)
|
127
127
|
#
|
128
128
|
# @param [ Array<Document> ] docs The docs to persist.
|
@@ -228,7 +228,7 @@ module Mongoid
|
|
228
228
|
def normalize_docs(docs)
|
229
229
|
if docs.first.is_a?(::Hash)
|
230
230
|
docs.map do |doc|
|
231
|
-
attributes = {
|
231
|
+
attributes = { _association: _association, _parent: _base }
|
232
232
|
attributes.merge!(doc)
|
233
233
|
Factory.build(klass, attributes)
|
234
234
|
end
|
@@ -278,7 +278,7 @@ module Mongoid
|
|
278
278
|
#
|
279
279
|
# @since 3.0.0
|
280
280
|
def selector
|
281
|
-
@selector ||=
|
281
|
+
@selector ||= _base.atomic_selector
|
282
282
|
end
|
283
283
|
|
284
284
|
# Pre processes the batch insert for the provided documents.
|
@@ -327,10 +327,10 @@ module Mongoid
|
|
327
327
|
self.path = doc.atomic_path unless path
|
328
328
|
execute_callback :before_remove, doc
|
329
329
|
unless _assigning?
|
330
|
-
doc.
|
330
|
+
doc.apply_delete_dependencies!
|
331
331
|
doc.run_before_callbacks(:destroy) if method == :destroy
|
332
332
|
end
|
333
|
-
|
333
|
+
_target.delete_one(doc)
|
334
334
|
_unscoped.delete_one(doc)
|
335
335
|
unbind_one(doc)
|
336
336
|
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,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
|
data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb}
RENAMED
@@ -1,9 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
module Mongoid
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
2
|
+
module Association
|
3
|
+
module Embedded
|
4
|
+
class EmbeddedIn
|
5
|
+
|
6
|
+
# The Builder behavior for embedded_in associations.
|
7
|
+
#
|
8
|
+
# @since 7.0
|
9
|
+
module Buildable
|
10
|
+
include Threaded::Lifecycle
|
7
11
|
|
8
12
|
# This builder doesn't actually build anything, just returns the
|
9
13
|
# parent since it should already be instantiated.
|
@@ -11,10 +15,12 @@ module Mongoid
|
|
11
15
|
# @example Build the document.
|
12
16
|
# Builder.new(meta, attrs).build
|
13
17
|
#
|
18
|
+
# @param [ Object ] base The object.
|
19
|
+
# @param [ Object ] object The parent hash or document.
|
14
20
|
# @param [ String ] type Not used in this context.
|
15
21
|
#
|
16
22
|
# @return [ Document ] A single document.
|
17
|
-
def build(type = nil)
|
23
|
+
def build(base, object, type = nil)
|
18
24
|
return object unless object.is_a?(Hash)
|
19
25
|
if _loading?
|
20
26
|
Factory.from_db(klass, object)
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Association
|
3
|
+
module Embedded
|
4
|
+
class EmbeddedIn
|
5
|
+
|
6
|
+
class Proxy < Association::One
|
7
|
+
|
8
|
+
# Instantiate a new embedded_in relation.
|
9
|
+
#
|
10
|
+
# @example Create the new relation.
|
11
|
+
# Association::Embedded::EmbeddedIn.new(person, address, association)
|
12
|
+
#
|
13
|
+
# @param [ Document ] base The document the relation hangs off of.
|
14
|
+
# @param [ Document ] target The target (parent) of the relation.
|
15
|
+
# @param [ Association ] association The association metadata.
|
16
|
+
#
|
17
|
+
# @return [ In ] The proxy.
|
18
|
+
def initialize(base, target, association)
|
19
|
+
init(base, target, association) do
|
20
|
+
characterize_one(_target)
|
21
|
+
bind_one
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Substitutes the supplied target documents for the existing document
|
26
|
+
# in the relation.
|
27
|
+
#
|
28
|
+
# @example Substitute the new document.
|
29
|
+
# person.name.substitute(new_name)
|
30
|
+
#
|
31
|
+
# @param [ Document ] replacement A document to replace the target.
|
32
|
+
#
|
33
|
+
# @return [ Document, nil ] The relation or nil.
|
34
|
+
#
|
35
|
+
# @since 2.0.0.rc.1
|
36
|
+
def substitute(replacement)
|
37
|
+
unbind_one
|
38
|
+
unless replacement
|
39
|
+
_base.delete if persistable?
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
_base.new_record = true
|
43
|
+
self._target = replacement
|
44
|
+
bind_one
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Instantiate the binding associated with this relation.
|
51
|
+
#
|
52
|
+
# @example Get the binding.
|
53
|
+
# binding([ address ])
|
54
|
+
#
|
55
|
+
# @return [ Binding ] A binding object.
|
56
|
+
#
|
57
|
+
# @since 2.0.0.rc.1
|
58
|
+
def binding
|
59
|
+
Binding.new(_base, _target, _association)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Characterize the document.
|
63
|
+
#
|
64
|
+
# @example Set the base association.
|
65
|
+
# object.characterize_one(document)
|
66
|
+
#
|
67
|
+
# @param [ Document ] document The document to set the association metadata on.
|
68
|
+
#
|
69
|
+
# @since 2.1.0
|
70
|
+
def characterize_one(document)
|
71
|
+
unless _base._association
|
72
|
+
_base._association = _association.inverse_association(document)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Are we able to persist this relation?
|
77
|
+
#
|
78
|
+
# @example Can we persist the relation?
|
79
|
+
# relation.persistable?
|
80
|
+
#
|
81
|
+
# @return [ true, false ] If the relation is persistable.
|
82
|
+
#
|
83
|
+
# @since 2.1.0
|
84
|
+
def persistable?
|
85
|
+
_target.persisted? && !_binding? && !_building?
|
86
|
+
end
|
87
|
+
|
88
|
+
class << self
|
89
|
+
|
90
|
+
# Returns true if the relation is an embedded one. In this case
|
91
|
+
# always true.
|
92
|
+
#
|
93
|
+
# @example Is this relation embedded?
|
94
|
+
# Association::Embedded::EmbeddedIn.embedded?
|
95
|
+
#
|
96
|
+
# @return [ true ] true.
|
97
|
+
#
|
98
|
+
# @since 2.0.0.rc.1
|
99
|
+
def embedded?
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
# Get the path calculator for the supplied document.
|
104
|
+
#
|
105
|
+
# @example Get the path calculator.
|
106
|
+
# Proxy.path(document)
|
107
|
+
#
|
108
|
+
# @param [ Document ] document The document to calculate on.
|
109
|
+
#
|
110
|
+
# @return [ Root ] The root atomic path calculator.
|
111
|
+
#
|
112
|
+
# @since 2.1.0
|
113
|
+
def path(document)
|
114
|
+
Mongoid::Atomic::Paths::Root.new(document)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|