mongoid 6.4.8 → 7.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE +1 -0
- data/README.md +4 -3
- data/Rakefile +33 -7
- 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 +211 -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 +174 -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 +45 -59
- 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 +511 -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/paths/embedded.rb +1 -1
- data/lib/mongoid/atomic.rb +14 -4
- data/lib/mongoid/attributes/dynamic.rb +16 -15
- 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 +55 -31
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/clients/sessions.rb +20 -4
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config/environment.rb +21 -8
- 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 +11 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -3
- data/lib/mongoid/criteria/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
- data/lib/mongoid/criteria/queryable/key.rb +67 -8
- data/lib/mongoid/criteria/queryable/mergeable.rb +5 -4
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +5 -3
- data/lib/mongoid/criteria/queryable/selector.rb +9 -31
- data/lib/mongoid/criteria.rb +9 -3
- data/lib/mongoid/document.rb +14 -4
- 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/hash.rb +9 -4
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/string.rb +2 -2
- 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 +5 -4
- data/lib/mongoid/indexable.rb +4 -1
- data/lib/mongoid/interceptable.rb +8 -6
- data/lib/mongoid/matchable/all.rb +4 -3
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/default.rb +71 -24
- 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/regexp.rb +2 -2
- data/lib/mongoid/matchable.rb +17 -16
- 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/pushable.rb +11 -2
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +26 -11
- data/lib/mongoid/positional.rb +1 -1
- data/lib/mongoid/query_cache.rb +4 -2
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/touchable.rb +102 -0
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/macros.rb +1 -1
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +5 -5
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +2 -1
- data/lib/mongoid.rb +1 -0
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/README.md +18 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/customer.rb +11 -0
- data/spec/app/models/customer_address.rb +12 -0
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/minim.rb +7 -0
- data/spec/app/models/other_owner_object.rb +2 -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/app_spec.rb +341 -0
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/integration/associations/embedded_spec.rb +176 -0
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/integration/criteria/date_field_spec.rb +41 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +32 -0
- data/spec/integration/matchable_spec.rb +680 -0
- data/spec/lite_spec_helper.rb +71 -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 → 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} +55 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +901 -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_models.rb +53 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +862 -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_dnl_models.rb +6 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +51 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +954 -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 +2023 -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} +247 -99
- 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 +227 -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} +30 -94
- 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 +1360 -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/paths_spec.rb +41 -0
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/dynamic_spec.rb +153 -0
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +298 -9
- data/spec/mongoid/clients/factory_spec.rb +20 -38
- data/spec/mongoid/clients/options_spec.rb +64 -50
- data/spec/mongoid/clients/sessions_spec.rb +9 -5
- data/spec/mongoid/clients/transactions_spec.rb +390 -0
- data/spec/mongoid/clients_spec.rb +70 -10
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/atomic_spec.rb +37 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +107 -56
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +173 -1
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +54 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +44 -1
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
- data/spec/mongoid/criteria/queryable/key_spec.rb +48 -6
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +762 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +5 -224
- data/spec/mongoid/criteria/queryable/selector_spec.rb +37 -0
- data/spec/mongoid/criteria_spec.rb +36 -19
- data/spec/mongoid/document_fields_spec.rb +88 -0
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/document_spec.rb +29 -4
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- 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/factory_spec.rb +21 -3
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +24 -12
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/default_spec.rb +10 -3
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable/eq_spec.rb +48 -0
- data/spec/mongoid/matchable/regexp_spec.rb +2 -2
- data/spec/mongoid/matchable_spec.rb +2 -2
- data/spec/mongoid/persistable/pushable_spec.rb +55 -1
- data/spec/mongoid/persistable/savable_spec.rb +5 -5
- data/spec/mongoid/persistable/settable_spec.rb +125 -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 +65 -27
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- 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/uniqueness_spec.rb +33 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +354 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +162 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- data/spec/spec_helper.rb +34 -49
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +21 -76
- data/spec/support/expectations.rb +17 -3
- data/spec/support/spec_config.rb +20 -7
- data.tar.gz.sig +0 -0
- metadata +646 -541
- metadata.gz.sig +1 -5
- 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
@@ -0,0 +1,552 @@
|
|
1
|
+
require 'mongoid/association/embedded/batchable'
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
module Association
|
5
|
+
module Embedded
|
6
|
+
class EmbedsMany
|
7
|
+
|
8
|
+
class Proxy < Association::Many
|
9
|
+
include Batchable
|
10
|
+
|
11
|
+
# Appends a document or array of documents to the relation. Will set
|
12
|
+
# the parent and update the index in the process.
|
13
|
+
#
|
14
|
+
# @example Append a document.
|
15
|
+
# person.addresses << address
|
16
|
+
#
|
17
|
+
# @example Push a document.
|
18
|
+
# person.addresses.push(address)
|
19
|
+
#
|
20
|
+
# @param [ Document, Array<Document> ] args Any number of documents.
|
21
|
+
def <<(*args)
|
22
|
+
docs = args.flatten
|
23
|
+
return concat(docs) if docs.size > 1
|
24
|
+
if doc = docs.first
|
25
|
+
append(doc)
|
26
|
+
doc.save if persistable? && !_assigning?
|
27
|
+
end
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
alias :push :<<
|
32
|
+
|
33
|
+
# Get this relation as as its representation in the database.
|
34
|
+
#
|
35
|
+
# @example Convert the relation to an attributes hash.
|
36
|
+
# person.addresses.as_document
|
37
|
+
#
|
38
|
+
# @return [ Array<Hash> ] The relation as stored in the db.
|
39
|
+
#
|
40
|
+
# @since 2.0.0.rc.1
|
41
|
+
def as_document
|
42
|
+
as_attributes.collect { |attrs| BSON::Document.new(attrs) }
|
43
|
+
end
|
44
|
+
|
45
|
+
# Appends an array of documents to the relation. Performs a batch
|
46
|
+
# insert of the documents instead of persisting one at a time.
|
47
|
+
#
|
48
|
+
# @example Concat with other documents.
|
49
|
+
# person.addresses.concat([ address_one, address_two ])
|
50
|
+
#
|
51
|
+
# @param [ Array<Document> ] docs The docs to add.
|
52
|
+
#
|
53
|
+
# @return [ Array<Document> ] The documents.
|
54
|
+
#
|
55
|
+
# @since 2.4.0
|
56
|
+
def concat(docs)
|
57
|
+
batch_insert(docs) unless docs.empty?
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Builds a new document in the relation and appends it to the target.
|
62
|
+
# Takes an optional type if you want to specify a subclass.
|
63
|
+
#
|
64
|
+
# @example Build a new document on the relation.
|
65
|
+
# person.people.build(:name => "Bozo")
|
66
|
+
#
|
67
|
+
# @param [ Hash ] attributes The attributes to build the document with.
|
68
|
+
# @param [ Class ] type Optional class to build the document with.
|
69
|
+
#
|
70
|
+
# @return [ Document ] The new document.
|
71
|
+
def build(attributes = {}, type = nil)
|
72
|
+
doc = Factory.build(type || _association.klass, attributes)
|
73
|
+
append(doc)
|
74
|
+
doc.apply_post_processed_defaults
|
75
|
+
yield(doc) if block_given?
|
76
|
+
doc.run_callbacks(:build) { doc }
|
77
|
+
_base._reset_memoized_children!
|
78
|
+
doc
|
79
|
+
end
|
80
|
+
|
81
|
+
alias :new :build
|
82
|
+
|
83
|
+
# Clear the relation. Will delete the documents from the db if they are
|
84
|
+
# already persisted.
|
85
|
+
#
|
86
|
+
# @example Clear the relation.
|
87
|
+
# person.addresses.clear
|
88
|
+
#
|
89
|
+
# @return [ self ] The empty relation.
|
90
|
+
def clear
|
91
|
+
batch_clear(_target.dup)
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
# Returns a count of the number of documents in the association that have
|
96
|
+
# actually been persisted to the database.
|
97
|
+
#
|
98
|
+
# Use #size if you want the total number of documents.
|
99
|
+
#
|
100
|
+
# @example Get the count of persisted documents.
|
101
|
+
# person.addresses.count
|
102
|
+
#
|
103
|
+
# @return [ Integer ] The total number of persisted embedded docs, as
|
104
|
+
# flagged by the #persisted? method.
|
105
|
+
def count
|
106
|
+
_target.select { |doc| doc.persisted? }.size
|
107
|
+
end
|
108
|
+
|
109
|
+
# Delete the supplied document from the target. This method is proxied
|
110
|
+
# in order to reindex the array after the operation occurs.
|
111
|
+
#
|
112
|
+
# @example Delete the document from the relation.
|
113
|
+
# person.addresses.delete(address)
|
114
|
+
#
|
115
|
+
# @param [ Document ] document The document to be deleted.
|
116
|
+
#
|
117
|
+
# @return [ Document, nil ] The deleted document or nil if nothing deleted.
|
118
|
+
#
|
119
|
+
# @since 2.0.0.rc.1
|
120
|
+
def delete(document)
|
121
|
+
execute_callback :before_remove, document
|
122
|
+
doc = _target.delete_one(document)
|
123
|
+
if doc && !_binding?
|
124
|
+
_unscoped.delete_one(doc)
|
125
|
+
if _assigning?
|
126
|
+
_base.add_atomic_pull(doc)
|
127
|
+
else
|
128
|
+
doc.delete(suppress: true)
|
129
|
+
unbind_one(doc)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
reindex
|
133
|
+
execute_callback :after_remove, document
|
134
|
+
doc
|
135
|
+
end
|
136
|
+
|
137
|
+
# Delete all the documents in the association without running callbacks.
|
138
|
+
#
|
139
|
+
# @example Delete all documents from the relation.
|
140
|
+
# person.addresses.delete_all
|
141
|
+
#
|
142
|
+
# @example Conditionally delete documents from the relation.
|
143
|
+
# person.addresses.delete_all({ :street => "Bond" })
|
144
|
+
#
|
145
|
+
# @param [ Hash ] conditions Conditions on which documents to delete.
|
146
|
+
#
|
147
|
+
# @return [ Integer ] The number of documents deleted.
|
148
|
+
def delete_all(conditions = {})
|
149
|
+
remove_all(conditions, :delete)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Delete all the documents for which the provided block returns true.
|
153
|
+
#
|
154
|
+
# @example Delete the matching documents.
|
155
|
+
# person.addresses.delete_if do |doc|
|
156
|
+
# doc.state == "GA"
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# @return [ Many, Enumerator ] The relation or an enumerator if no
|
160
|
+
# block was provided.
|
161
|
+
#
|
162
|
+
# @since 3.1.0
|
163
|
+
def delete_if
|
164
|
+
if block_given?
|
165
|
+
dup_target = _target.dup
|
166
|
+
dup_target.each do |doc|
|
167
|
+
delete(doc) if yield(doc)
|
168
|
+
end
|
169
|
+
self
|
170
|
+
else
|
171
|
+
super
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Destroy all the documents in the association whilst running callbacks.
|
176
|
+
#
|
177
|
+
# @example Destroy all documents from the relation.
|
178
|
+
# person.addresses.destroy_all
|
179
|
+
#
|
180
|
+
# @example Conditionally destroy documents from the relation.
|
181
|
+
# person.addresses.destroy_all({ :street => "Bond" })
|
182
|
+
#
|
183
|
+
# @param [ Hash ] conditions Conditions on which documents to destroy.
|
184
|
+
#
|
185
|
+
# @return [ Integer ] The number of documents destroyed.
|
186
|
+
def destroy_all(conditions = {})
|
187
|
+
remove_all(conditions, :destroy)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Determine if any documents in this relation exist in the database.
|
191
|
+
#
|
192
|
+
# @example Are there persisted documents?
|
193
|
+
# person.posts.exists?
|
194
|
+
#
|
195
|
+
# @return [ true, false ] True is persisted documents exist, false if not.
|
196
|
+
def exists?
|
197
|
+
count > 0
|
198
|
+
end
|
199
|
+
|
200
|
+
# Finds a document in this association through several different
|
201
|
+
# methods.
|
202
|
+
#
|
203
|
+
# @example Find a document by its id.
|
204
|
+
# person.addresses.find(BSON::ObjectId.new)
|
205
|
+
#
|
206
|
+
# @example Find documents for multiple ids.
|
207
|
+
# person.addresses.find([ BSON::ObjectId.new, BSON::ObjectId.new ])
|
208
|
+
#
|
209
|
+
# @param [ Array<Object> ] args Various arguments.
|
210
|
+
#
|
211
|
+
# @return [ Array<Document>, Document ] A single or multiple documents.
|
212
|
+
def find(*args)
|
213
|
+
criteria.find(*args)
|
214
|
+
end
|
215
|
+
|
216
|
+
# Instantiate a new embeds_many relation.
|
217
|
+
#
|
218
|
+
# @example Create the new relation.
|
219
|
+
# Many.new(person, addresses, association)
|
220
|
+
#
|
221
|
+
# @param [ Document ] base The document this relation hangs off of.
|
222
|
+
# @param [ Array<Document> ] target The child documents of the relation.
|
223
|
+
# @param [ Association ] association The association metadata
|
224
|
+
#
|
225
|
+
# @return [ Many ] The proxy.
|
226
|
+
def initialize(base, target, association)
|
227
|
+
init(base, target, association) do
|
228
|
+
_target.each_with_index do |doc, index|
|
229
|
+
integrate(doc)
|
230
|
+
doc._index = index
|
231
|
+
end
|
232
|
+
@_unscoped = _target.dup
|
233
|
+
@_target = scope(_target)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Get all the documents in the relation that are loaded into memory.
|
238
|
+
#
|
239
|
+
# @example Get the in memory documents.
|
240
|
+
# relation.in_memory
|
241
|
+
#
|
242
|
+
# @return [ Array<Document> ] The documents in memory.
|
243
|
+
#
|
244
|
+
# @since 2.1.0
|
245
|
+
def in_memory
|
246
|
+
_target
|
247
|
+
end
|
248
|
+
|
249
|
+
# Pop documents off the relation. This can be a single document or
|
250
|
+
# multiples, and will automatically persist the changes.
|
251
|
+
#
|
252
|
+
# @example Pop a single document.
|
253
|
+
# relation.pop
|
254
|
+
#
|
255
|
+
# @example Pop multiple documents.
|
256
|
+
# relation.pop(3)
|
257
|
+
#
|
258
|
+
# @param [ Integer ] count The number of documents to pop, or 1 if not
|
259
|
+
# provided.
|
260
|
+
#
|
261
|
+
# @return [ Document, Array<Document> ] The popped document(s).
|
262
|
+
#
|
263
|
+
# @since 3.0.0
|
264
|
+
def pop(count = nil)
|
265
|
+
if count
|
266
|
+
if docs = _target[_target.size - count, _target.size]
|
267
|
+
docs.each { |doc| delete(doc) }
|
268
|
+
end
|
269
|
+
else
|
270
|
+
delete(_target[-1])
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# Shift documents off the relation. This can be a single document or
|
275
|
+
# multiples, and will automatically persist the changes.
|
276
|
+
#
|
277
|
+
# @example Shift a single document.
|
278
|
+
# relation.shift
|
279
|
+
#
|
280
|
+
# @example Shift multiple documents.
|
281
|
+
# relation.shift(3)
|
282
|
+
#
|
283
|
+
# @param [ Integer ] count The number of documents to shift, or 1 if not
|
284
|
+
# provided.
|
285
|
+
#
|
286
|
+
# @return [ Document, Array<Document> ] The shifted document(s).
|
287
|
+
def shift(count = nil)
|
288
|
+
if count
|
289
|
+
if _target.size > 0 && docs = _target[0, count]
|
290
|
+
docs.each { |doc| delete(doc) }
|
291
|
+
end
|
292
|
+
else
|
293
|
+
delete(_target[0])
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
# Substitutes the supplied target documents for the existing documents
|
298
|
+
# in the relation.
|
299
|
+
#
|
300
|
+
# @example Substitute the relation's target.
|
301
|
+
# person.addresses.substitute([ address ])
|
302
|
+
#
|
303
|
+
# @param [ Array<Document> ] docs The replacement docs.
|
304
|
+
#
|
305
|
+
# @return [ Many ] The proxied relation.
|
306
|
+
#
|
307
|
+
# @since 2.0.0.rc.1
|
308
|
+
def substitute(docs)
|
309
|
+
batch_replace(docs)
|
310
|
+
self
|
311
|
+
end
|
312
|
+
|
313
|
+
# Return the relation with all previous scoping removed. This is the
|
314
|
+
# exact representation of the docs in the database.
|
315
|
+
#
|
316
|
+
# @example Get the unscoped documents.
|
317
|
+
# person.addresses.unscoped
|
318
|
+
#
|
319
|
+
# @return [ Criteria ] The unscoped relation.
|
320
|
+
#
|
321
|
+
# @since 2.4.0
|
322
|
+
def unscoped
|
323
|
+
criterion = klass.unscoped
|
324
|
+
criterion.embedded = true
|
325
|
+
criterion.documents = _unscoped.delete_if(&:marked_for_destruction?)
|
326
|
+
criterion
|
327
|
+
end
|
328
|
+
|
329
|
+
private
|
330
|
+
|
331
|
+
def object_already_related?(document)
|
332
|
+
_target.any? { |existing| existing.id && existing === document }
|
333
|
+
end
|
334
|
+
|
335
|
+
# Appends the document to the target array, updating the index on the
|
336
|
+
# document at the same time.
|
337
|
+
#
|
338
|
+
# @example Append to the document.
|
339
|
+
# relation.append(document)
|
340
|
+
#
|
341
|
+
# @param [ Document ] document The document to append to the target.
|
342
|
+
#
|
343
|
+
# @since 2.0.0.rc.1
|
344
|
+
def append(document)
|
345
|
+
execute_callback :before_add, document
|
346
|
+
unless object_already_related?(document)
|
347
|
+
_target.push(*scope([document]))
|
348
|
+
end
|
349
|
+
_unscoped.push(document)
|
350
|
+
integrate(document)
|
351
|
+
document._index = _unscoped.size - 1
|
352
|
+
execute_callback :after_add, document
|
353
|
+
end
|
354
|
+
|
355
|
+
# Instantiate the binding associated with this relation.
|
356
|
+
#
|
357
|
+
# @example Create the binding.
|
358
|
+
# relation.binding([ address ])
|
359
|
+
#
|
360
|
+
# @return [ Binding ] The many binding.
|
361
|
+
#
|
362
|
+
# @since 2.0.0.rc.1
|
363
|
+
def binding
|
364
|
+
Binding.new(_base, _target, _association)
|
365
|
+
end
|
366
|
+
|
367
|
+
# Returns the +Criteria+ object for the target class with its
|
368
|
+
# documents set to the list of target documents in the association.
|
369
|
+
#
|
370
|
+
# @return [ Criteria ] A new criteria.
|
371
|
+
def criteria
|
372
|
+
_association.criteria(_base, _target)
|
373
|
+
end
|
374
|
+
|
375
|
+
# Deletes one document from the target and unscoped.
|
376
|
+
#
|
377
|
+
# @api private
|
378
|
+
#
|
379
|
+
# @example Delete one document.
|
380
|
+
# relation.delete_one(doc)
|
381
|
+
#
|
382
|
+
# @param [ Document ] document The document to delete.
|
383
|
+
#
|
384
|
+
# @since 2.4.7
|
385
|
+
def delete_one(document)
|
386
|
+
_target.delete_one(document)
|
387
|
+
_unscoped.delete_one(document)
|
388
|
+
reindex
|
389
|
+
end
|
390
|
+
|
391
|
+
# Integrate the document into the relation. will set its metadata and
|
392
|
+
# attempt to bind the inverse.
|
393
|
+
#
|
394
|
+
# @example Integrate the document.
|
395
|
+
# relation.integrate(document)
|
396
|
+
#
|
397
|
+
# @param [ Document ] document The document to integrate.
|
398
|
+
#
|
399
|
+
# @since 2.1.0
|
400
|
+
def integrate(document)
|
401
|
+
characterize_one(document)
|
402
|
+
bind_one(document)
|
403
|
+
end
|
404
|
+
|
405
|
+
# If the target array does not respond to the supplied method then try to
|
406
|
+
# find a named scope or criteria on the class and send the call there.
|
407
|
+
#
|
408
|
+
# If the method exists on the array, use the default proxy behavior.
|
409
|
+
#
|
410
|
+
# @param [ Symbol, String ] name The name of the method.
|
411
|
+
# @param [ Array ] args The method args
|
412
|
+
# @param [ Proc ] block Optional block to pass.
|
413
|
+
#
|
414
|
+
# @return [ Criteria, Object ] A Criteria or return value from the target.
|
415
|
+
def method_missing(name, *args, &block)
|
416
|
+
return super if _target.respond_to?(name)
|
417
|
+
klass.send(:with_scope, criteria) do
|
418
|
+
criteria.public_send(name, *args, &block)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
# Are we able to persist this relation?
|
423
|
+
#
|
424
|
+
# @example Can we persist the relation?
|
425
|
+
# relation.persistable?
|
426
|
+
#
|
427
|
+
# @return [ true, false ] If the relation is persistable.
|
428
|
+
#
|
429
|
+
# @since 2.1.0
|
430
|
+
def persistable?
|
431
|
+
_base.persisted? && !_binding?
|
432
|
+
end
|
433
|
+
|
434
|
+
# Reindex all the target elements. This is useful when performing
|
435
|
+
# operations on the proxied target directly and the indices need to
|
436
|
+
# match that on the database side.
|
437
|
+
#
|
438
|
+
# @example Reindex the relation.
|
439
|
+
# person.addresses.reindex
|
440
|
+
#
|
441
|
+
# @since 2.0.0.rc.1
|
442
|
+
def reindex
|
443
|
+
_unscoped.each_with_index do |doc, index|
|
444
|
+
doc._index = index
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
# Apply the association ordering and default scoping (defined on
|
449
|
+
# association's target class) to the provided documents.
|
450
|
+
#
|
451
|
+
# @example Apply scoping.
|
452
|
+
# person.addresses.scope(target)
|
453
|
+
#
|
454
|
+
# @param [ Array<Document> ] docs The documents to scope.
|
455
|
+
#
|
456
|
+
# @return [ Array<Document> ] The scoped docs.
|
457
|
+
#
|
458
|
+
# @since 2.4.0
|
459
|
+
def scope(docs)
|
460
|
+
unless _association.order || _association.klass.default_scoping?
|
461
|
+
return docs
|
462
|
+
end
|
463
|
+
|
464
|
+
crit = _association.klass.order_by(_association.order)
|
465
|
+
crit.embedded = true
|
466
|
+
crit.documents = docs
|
467
|
+
crit.entries
|
468
|
+
end
|
469
|
+
|
470
|
+
# Remove all documents from the relation, either with a delete or a
|
471
|
+
# destroy depending on what this was called through.
|
472
|
+
#
|
473
|
+
# @example Destroy documents from the relation.
|
474
|
+
# relation.remove_all({ :num => 1 }, true)
|
475
|
+
#
|
476
|
+
# @param [ Hash ] conditions Conditions to filter by.
|
477
|
+
# @param [ true, false ] method :delete or :destroy.
|
478
|
+
#
|
479
|
+
# @return [ Integer ] The number of documents removed.
|
480
|
+
def remove_all(conditions = {}, method = :delete)
|
481
|
+
criteria = where(conditions || {})
|
482
|
+
removed = criteria.size
|
483
|
+
batch_remove(criteria, method)
|
484
|
+
removed
|
485
|
+
end
|
486
|
+
|
487
|
+
# Get the internal unscoped documents.
|
488
|
+
#
|
489
|
+
# @example Get the unscoped documents.
|
490
|
+
# relation._unscoped
|
491
|
+
#
|
492
|
+
# @return [ Array<Document> ] The unscoped documents.
|
493
|
+
#
|
494
|
+
# @since 2.4.0
|
495
|
+
def _unscoped
|
496
|
+
@_unscoped ||= []
|
497
|
+
end
|
498
|
+
|
499
|
+
# Set the internal unscoped documents.
|
500
|
+
#
|
501
|
+
# @example Set the unscoped documents.
|
502
|
+
# relation._unscoped = docs
|
503
|
+
#
|
504
|
+
# @param [ Array<Document> ] docs The documents.
|
505
|
+
#
|
506
|
+
# @return [ Array<Document ] The unscoped docs.
|
507
|
+
#
|
508
|
+
# @since 2.4.0
|
509
|
+
def _unscoped=(docs)
|
510
|
+
@_unscoped = docs
|
511
|
+
end
|
512
|
+
|
513
|
+
def as_attributes
|
514
|
+
attributes = []
|
515
|
+
_unscoped.each do |doc|
|
516
|
+
attributes.push(doc.as_document)
|
517
|
+
end
|
518
|
+
attributes
|
519
|
+
end
|
520
|
+
|
521
|
+
class << self
|
522
|
+
|
523
|
+
# Returns true if the relation is an embedded one. In this case
|
524
|
+
# always true.
|
525
|
+
#
|
526
|
+
# @example Is the relation embedded?
|
527
|
+
# Association::Embedded::EmbedsMany.embedded?
|
528
|
+
#
|
529
|
+
# @return [ true ] true.
|
530
|
+
#
|
531
|
+
# @since 2.0.0.rc.1
|
532
|
+
def embedded?
|
533
|
+
true
|
534
|
+
end
|
535
|
+
|
536
|
+
# Returns the suffix of the foreign key field, either "_id" or "_ids".
|
537
|
+
#
|
538
|
+
# @example Get the suffix for the foreign key.
|
539
|
+
# Association::Embedded::EmbedsMany.foreign_key_suffix
|
540
|
+
#
|
541
|
+
# @return [ nil ] nil.
|
542
|
+
#
|
543
|
+
# @since 3.0.0
|
544
|
+
def foreign_key_suffix
|
545
|
+
nil
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|