mongoid 6.4.8 → 7.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -4,7 +4,7 @@ require "mongoid/contextual/aggregable/mongo"
|
|
|
4
4
|
require "mongoid/contextual/command"
|
|
5
5
|
require "mongoid/contextual/geo_near"
|
|
6
6
|
require "mongoid/contextual/map_reduce"
|
|
7
|
-
require "mongoid/
|
|
7
|
+
require "mongoid/association/eager_loadable"
|
|
8
8
|
|
|
9
9
|
module Mongoid
|
|
10
10
|
module Contextual
|
|
@@ -12,7 +12,7 @@ module Mongoid
|
|
|
12
12
|
include Enumerable
|
|
13
13
|
include Aggregable::Mongo
|
|
14
14
|
include Atomic
|
|
15
|
-
include
|
|
15
|
+
include Association::EagerLoadable
|
|
16
16
|
include Queryable
|
|
17
17
|
|
|
18
18
|
# Options constant.
|
|
@@ -256,12 +256,12 @@ module Mongoid
|
|
|
256
256
|
try_cache(:first) do
|
|
257
257
|
if sort = view.sort || ({ _id: 1 } unless opts[:id_sort] == :none)
|
|
258
258
|
if raw_doc = view.sort(sort).limit(-1).first
|
|
259
|
-
doc = Factory.from_db(klass, raw_doc, criteria
|
|
259
|
+
doc = Factory.from_db(klass, raw_doc, criteria)
|
|
260
260
|
eager_load([doc]).first
|
|
261
261
|
end
|
|
262
262
|
else
|
|
263
263
|
if raw_doc = view.limit(-1).first
|
|
264
|
-
doc = Factory.from_db(klass, raw_doc, criteria
|
|
264
|
+
doc = Factory.from_db(klass, raw_doc, criteria)
|
|
265
265
|
eager_load([doc]).first
|
|
266
266
|
end
|
|
267
267
|
end
|
|
@@ -277,7 +277,7 @@ module Mongoid
|
|
|
277
277
|
def find_first
|
|
278
278
|
return documents.first if cached? && cache_loaded?
|
|
279
279
|
if raw_doc = view.first
|
|
280
|
-
doc = Factory.from_db(klass, raw_doc, criteria
|
|
280
|
+
doc = Factory.from_db(klass, raw_doc, criteria)
|
|
281
281
|
eager_load([doc]).first
|
|
282
282
|
end
|
|
283
283
|
end
|
|
@@ -368,7 +368,7 @@ module Mongoid
|
|
|
368
368
|
try_cache(:last) do
|
|
369
369
|
with_inverse_sorting(opts) do
|
|
370
370
|
if raw_doc = view.limit(-1).first
|
|
371
|
-
doc = Factory.from_db(klass, raw_doc, criteria
|
|
371
|
+
doc = Factory.from_db(klass, raw_doc, criteria)
|
|
372
372
|
eager_load([doc]).first
|
|
373
373
|
end
|
|
374
374
|
end
|
|
@@ -683,7 +683,7 @@ module Mongoid
|
|
|
683
683
|
def documents_for_iteration
|
|
684
684
|
return documents if cached? && !documents.empty?
|
|
685
685
|
return view unless eager_loadable?
|
|
686
|
-
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria
|
|
686
|
+
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria) }
|
|
687
687
|
eager_load(docs)
|
|
688
688
|
end
|
|
689
689
|
|
|
@@ -701,11 +701,13 @@ module Mongoid
|
|
|
701
701
|
# @since 3.0.0
|
|
702
702
|
def yield_document(document, &block)
|
|
703
703
|
doc = document.respond_to?(:_id) ?
|
|
704
|
-
document : Factory.from_db(klass, document, criteria
|
|
704
|
+
document : Factory.from_db(klass, document, criteria)
|
|
705
705
|
yield(doc)
|
|
706
706
|
documents.push(doc) if cacheable?
|
|
707
707
|
end
|
|
708
708
|
|
|
709
|
+
private
|
|
710
|
+
|
|
709
711
|
def _session
|
|
710
712
|
@criteria.send(:_session)
|
|
711
713
|
end
|
data/lib/mongoid/copyable.rb
CHANGED
|
@@ -69,15 +69,20 @@ module Mongoid
|
|
|
69
69
|
attrs["#{name}_translations"] = value
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
klass.embedded_relations.each do |_,
|
|
73
|
-
next unless attrs.present? && attrs[
|
|
72
|
+
klass.embedded_relations.each do |_, association|
|
|
73
|
+
next unless attrs.present? && attrs[association.key].present?
|
|
74
74
|
|
|
75
|
-
if
|
|
76
|
-
attrs[
|
|
77
|
-
|
|
75
|
+
if association.is_a?(Association::Embedded::EmbedsMany)
|
|
76
|
+
attrs[association.key].each do |attr|
|
|
77
|
+
embedded_klass = if type = attr['_type']
|
|
78
|
+
type.constantize
|
|
79
|
+
else
|
|
80
|
+
association.relation_class
|
|
81
|
+
end
|
|
82
|
+
process_localized_attributes(embedded_klass, attr)
|
|
78
83
|
end
|
|
79
84
|
else
|
|
80
|
-
process_localized_attributes(
|
|
85
|
+
process_localized_attributes(association.klass, attrs[association.key])
|
|
81
86
|
end
|
|
82
87
|
end
|
|
83
88
|
end
|
|
@@ -36,7 +36,7 @@ module Mongoid
|
|
|
36
36
|
# @example Get the eager loading inclusions.
|
|
37
37
|
# Person.includes(:game).inclusions
|
|
38
38
|
#
|
|
39
|
-
# @return [ Array<
|
|
39
|
+
# @return [ Array<Association> ] The inclusions.
|
|
40
40
|
#
|
|
41
41
|
# @since 2.2.0
|
|
42
42
|
def inclusions
|
|
@@ -46,11 +46,11 @@ module Mongoid
|
|
|
46
46
|
# Set the inclusions for the criteria.
|
|
47
47
|
#
|
|
48
48
|
# @example Set the inclusions.
|
|
49
|
-
# criteria.inclusions = [
|
|
49
|
+
# criteria.inclusions = [ association ]
|
|
50
50
|
#
|
|
51
|
-
# @param [ Array<
|
|
51
|
+
# @param [ Array<Association> ] value The inclusions.
|
|
52
52
|
#
|
|
53
|
-
# @return [ Array<
|
|
53
|
+
# @return [ Array<Association> ] The new inclusions.
|
|
54
54
|
#
|
|
55
55
|
# @since 3.0.0
|
|
56
56
|
def inclusions=(value)
|
|
@@ -65,28 +65,28 @@ module Mongoid
|
|
|
65
65
|
# criteria.add_inclusion(Person, :posts)
|
|
66
66
|
#
|
|
67
67
|
# @param [ Class, String, Symbol ] _klass The class or string/symbol of the class name.
|
|
68
|
-
# @param [ Symbol ]
|
|
68
|
+
# @param [ Symbol ] association The relation.
|
|
69
69
|
#
|
|
70
70
|
# @raise [ Errors::InvalidIncludes ] If no relation is found.
|
|
71
71
|
#
|
|
72
72
|
# @since 5.1.0
|
|
73
|
-
def add_inclusion(_klass,
|
|
74
|
-
inclusions.push(
|
|
73
|
+
def add_inclusion(_klass, association)
|
|
74
|
+
inclusions.push(association) unless inclusions.include?(association)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def extract_includes_list(_parent_class, *relations_list)
|
|
78
78
|
relations_list.flatten.each do |relation_object|
|
|
79
79
|
if relation_object.is_a?(Hash)
|
|
80
80
|
relation_object.each do |relation, _includes|
|
|
81
|
-
|
|
82
|
-
raise Errors::InvalidIncludes.new(_klass, [ relation ]) unless
|
|
83
|
-
add_inclusion(_parent_class,
|
|
84
|
-
extract_includes_list(
|
|
81
|
+
association = _parent_class.reflect_on_association(relation)
|
|
82
|
+
raise Errors::InvalidIncludes.new(_klass, [ relation ]) unless association
|
|
83
|
+
add_inclusion(_parent_class, association)
|
|
84
|
+
extract_includes_list(association.klass, _includes)
|
|
85
85
|
end
|
|
86
86
|
else
|
|
87
|
-
|
|
88
|
-
raise Errors::InvalidIncludes.new(_parent_class, [ relation_object ]) unless
|
|
89
|
-
add_inclusion(_parent_class,
|
|
87
|
+
association = _parent_class.reflect_on_association(relation_object)
|
|
88
|
+
raise Errors::InvalidIncludes.new(_parent_class, [ relation_object ]) unless association
|
|
89
|
+
add_inclusion(_parent_class, association)
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
end
|
|
@@ -72,7 +72,8 @@ module Mongoid
|
|
|
72
72
|
# @since 5.1.0
|
|
73
73
|
def create_with(attrs = {})
|
|
74
74
|
tap do
|
|
75
|
-
|
|
75
|
+
@create_attrs ||= {}
|
|
76
|
+
@create_attrs.update(attrs)
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
|
|
@@ -190,9 +191,13 @@ module Mongoid
|
|
|
190
191
|
end
|
|
191
192
|
if embedded?
|
|
192
193
|
attributes[:_parent] = parent_document
|
|
193
|
-
attributes[:
|
|
194
|
+
attributes[:_association] = association
|
|
195
|
+
end
|
|
196
|
+
if polymorphic? && @criterion
|
|
197
|
+
klass.__send__(method, attributes.merge(@criterion), &block)
|
|
198
|
+
else
|
|
199
|
+
klass.__send__(method, attributes, &block)
|
|
194
200
|
end
|
|
195
|
-
klass.__send__(method, attributes, &block)
|
|
196
201
|
end
|
|
197
202
|
|
|
198
203
|
# Find the first object or create/initialize it.
|
|
@@ -17,8 +17,8 @@ module Mongoid
|
|
|
17
17
|
PersistenceContext.set(klass, options)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def clear_persistence_context(original_cluster)
|
|
21
|
-
PersistenceContext.clear(klass, original_cluster)
|
|
20
|
+
def clear_persistence_context(original_cluster, original_context)
|
|
21
|
+
PersistenceContext.clear(klass, original_cluster, original_context)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -58,7 +58,7 @@ module Mongoid
|
|
|
58
58
|
#
|
|
59
59
|
# @since 1.0.0
|
|
60
60
|
def __numeric__(object)
|
|
61
|
-
object.to_s =~ /(
|
|
61
|
+
object.to_s =~ /(\A[-+]?[0-9]+\z)|(\.0+\z)|(\.\z)/ ? object.to_i : Float(object)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
# Evolve the object to an integer.
|
|
@@ -10,7 +10,7 @@ module Mongoid
|
|
|
10
10
|
# Is the object a regexp?
|
|
11
11
|
#
|
|
12
12
|
# @example Is the object a regex?
|
|
13
|
-
#
|
|
13
|
+
# /\A[123]/.regexp?
|
|
14
14
|
#
|
|
15
15
|
# @return [ true ] Always true.
|
|
16
16
|
#
|
|
@@ -22,7 +22,7 @@ module Mongoid
|
|
|
22
22
|
# Evolve the object into a regex.
|
|
23
23
|
#
|
|
24
24
|
# @example Evolve the object to a regex.
|
|
25
|
-
# Regexp.evolve("
|
|
25
|
+
# Regexp.evolve("\A[123]")
|
|
26
26
|
#
|
|
27
27
|
# @param [ Regexp, String ] object The object to evolve.
|
|
28
28
|
#
|
|
@@ -53,7 +53,7 @@ module Mongoid
|
|
|
53
53
|
# Evolve the object into a raw bson regex.
|
|
54
54
|
#
|
|
55
55
|
# @example Evolve the object to a regex.
|
|
56
|
-
# BSON::Regexp::Raw.evolve("
|
|
56
|
+
# BSON::Regexp::Raw.evolve("\\A[123]")
|
|
57
57
|
#
|
|
58
58
|
# @param [ BSON::Regexp::Raw, String ] object The object to evolve.
|
|
59
59
|
#
|
|
@@ -7,6 +7,18 @@ module Mongoid
|
|
|
7
7
|
# This module contains additional time with zone behaviour.
|
|
8
8
|
module TimeWithZone
|
|
9
9
|
|
|
10
|
+
# Evolve the time as a date, UTC midnight.
|
|
11
|
+
#
|
|
12
|
+
# @example Evolve the time to a date query format.
|
|
13
|
+
# time.__evolve_date__
|
|
14
|
+
#
|
|
15
|
+
# @return [ Time ] The date at midnight UTC.
|
|
16
|
+
#
|
|
17
|
+
# @since 1.0.0
|
|
18
|
+
def __evolve_date__
|
|
19
|
+
::Time.utc(year, month, day, 0, 0, 0, 0)
|
|
20
|
+
end
|
|
21
|
+
|
|
10
22
|
# Evolve the time into a utc time.
|
|
11
23
|
#
|
|
12
24
|
# @example Evolve the time.
|
|
@@ -3,16 +3,75 @@ module Mongoid
|
|
|
3
3
|
class Criteria
|
|
4
4
|
module Queryable
|
|
5
5
|
|
|
6
|
-
#
|
|
7
|
-
#
|
|
6
|
+
# Key objects represent specifications for building query expressions
|
|
7
|
+
# utilizing MongoDB selectors.
|
|
8
|
+
#
|
|
9
|
+
# Simple key-value conditions are translated directly into expression
|
|
10
|
+
# hashes by Mongoid without utilizing Key objects. For example, the
|
|
11
|
+
# following condition:
|
|
12
|
+
#
|
|
13
|
+
# Foo.where(price: 1)
|
|
14
|
+
#
|
|
15
|
+
# ... is translated to the following simple expression:
|
|
16
|
+
#
|
|
17
|
+
# {price: 1}
|
|
18
|
+
#
|
|
19
|
+
# More complex conditions would start involving Key objects. For example:
|
|
20
|
+
#
|
|
21
|
+
# Foo.where(:price.gt => 1)
|
|
22
|
+
#
|
|
23
|
+
# ... causes a Key instance to be created thusly:
|
|
24
|
+
#
|
|
25
|
+
# Key.new(:price, :__override__, '$gt')
|
|
26
|
+
#
|
|
27
|
+
# This Key instance utilizes +operator+ but not +expanded+ nor +block+.
|
|
28
|
+
# The corresponding MongoDB query expression is:
|
|
29
|
+
#
|
|
30
|
+
# {price: {'$gt' => 1}}
|
|
31
|
+
#
|
|
32
|
+
# A yet more more complex example is the following condition:
|
|
33
|
+
#
|
|
34
|
+
# Foo.geo_spacial(:boundary.intersects_point => [1, 10])
|
|
35
|
+
#
|
|
36
|
+
# Processing this condition will cause a Key instance to be created as
|
|
37
|
+
# follows:
|
|
38
|
+
#
|
|
39
|
+
# Key.new(:location, :__override__, '$geoIntersects', '$geometry') do |value|
|
|
40
|
+
# { "type" => POINT, "coordinates" => value }
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# ... eventually producing the following MongoDB query expression:
|
|
44
|
+
#
|
|
45
|
+
# {
|
|
46
|
+
# boundary: {
|
|
47
|
+
# '$geoIntersects' => {
|
|
48
|
+
# '$geometry' => {
|
|
49
|
+
# type: "Point" ,
|
|
50
|
+
# coordinates: [ 1, 10 ]
|
|
51
|
+
# }
|
|
52
|
+
# }
|
|
53
|
+
# }
|
|
54
|
+
# }
|
|
55
|
+
#
|
|
56
|
+
# Key instances can be thought of as procs that map a value to the
|
|
57
|
+
# MongoDB query expression required to obtain the key's condition,
|
|
58
|
+
# given the value.
|
|
8
59
|
class Key
|
|
9
60
|
|
|
10
|
-
# @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# @
|
|
14
|
-
|
|
15
|
-
|
|
61
|
+
# @return [ String | Symbol ] The name of the field.
|
|
62
|
+
attr_reader :name
|
|
63
|
+
|
|
64
|
+
# @return [ String ] The MongoDB query operator.
|
|
65
|
+
attr_reader :operator
|
|
66
|
+
|
|
67
|
+
# @return [ String ] The MongoDB expanded query operator.
|
|
68
|
+
attr_reader :expanded
|
|
69
|
+
|
|
70
|
+
# @return [ Symbol ] The name of the merge strategy.
|
|
71
|
+
attr_reader :strategy
|
|
72
|
+
|
|
73
|
+
# @return [ Proc ] The optional block to transform values.
|
|
74
|
+
attr_reader :block
|
|
16
75
|
|
|
17
76
|
# Does the key equal another object?
|
|
18
77
|
#
|
|
@@ -45,7 +45,7 @@ module Mongoid
|
|
|
45
45
|
use(:__union__)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
#
|
|
48
|
+
# Clear the current strategy and negating flag, used after cloning.
|
|
49
49
|
#
|
|
50
50
|
# @example Reset the strategies.
|
|
51
51
|
# mergeable.reset_strategies!
|
|
@@ -54,7 +54,8 @@ module Mongoid
|
|
|
54
54
|
#
|
|
55
55
|
# @since 1.0.0
|
|
56
56
|
def reset_strategies!
|
|
57
|
-
self.strategy
|
|
57
|
+
self.strategy = nil
|
|
58
|
+
self.negating = nil
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
private
|
|
@@ -167,7 +168,7 @@ module Mongoid
|
|
|
167
168
|
# @example Add the criterion.
|
|
168
169
|
# mergeable.__override__([ 1, 2 ], "$in")
|
|
169
170
|
#
|
|
170
|
-
# @param [ Hash ] criterion The criteria.
|
|
171
|
+
# @param [ Hash | Criteria ] criterion The criteria.
|
|
171
172
|
# @param [ String ] operator The MongoDB operator.
|
|
172
173
|
#
|
|
173
174
|
# @return [ Mergeable ] The new mergeable.
|
|
@@ -225,7 +226,7 @@ module Mongoid
|
|
|
225
226
|
# @api private
|
|
226
227
|
#
|
|
227
228
|
# @example Add criterion with a strategy.
|
|
228
|
-
# mergeable.with_strategy(:__union__, [ 1, 2, 3 ], "$in")
|
|
229
|
+
# mergeable.with_strategy(:__union__, {field_name: [ 1, 2, 3 ]}, "$in")
|
|
229
230
|
#
|
|
230
231
|
# @param [ Symbol ] strategy The name of the strategy method.
|
|
231
232
|
# @param [ Object ] criterion The criterion to add.
|
|
@@ -72,16 +72,21 @@ module Mongoid
|
|
|
72
72
|
#
|
|
73
73
|
# @example Add the unwind.
|
|
74
74
|
# pipeline.unwind(:field)
|
|
75
|
+
# pipeline.unwind(document)
|
|
75
76
|
#
|
|
76
|
-
# @param [ String, Symbol ]
|
|
77
|
+
# @param [ String, Symbol, Hash ] field_or_doc The name of the field or a document.
|
|
77
78
|
#
|
|
78
79
|
# @return [ Pipeline ] The pipeline.
|
|
79
80
|
#
|
|
80
81
|
# @since 2.0.0
|
|
81
|
-
def unwind(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
def unwind(field_or_doc)
|
|
83
|
+
unless field_or_doc.respond_to? :keys
|
|
84
|
+
normalized = field_or_doc.to_s
|
|
85
|
+
name = aliases[normalized] || normalized
|
|
86
|
+
push("$unwind" => name.__mongo_expression__)
|
|
87
|
+
else
|
|
88
|
+
push("$unwind" => field_or_doc)
|
|
89
|
+
end
|
|
85
90
|
end
|
|
86
91
|
|
|
87
92
|
private
|
|
@@ -434,7 +434,7 @@ module Mongoid
|
|
|
434
434
|
# @since 1.0.0
|
|
435
435
|
def not(*criterion)
|
|
436
436
|
if criterion.empty?
|
|
437
|
-
tap { |query| query.negating = true }
|
|
437
|
+
dup.tap { |query| query.negating = true }
|
|
438
438
|
else
|
|
439
439
|
__override__(criterion.first, "$not")
|
|
440
440
|
end
|
|
@@ -562,6 +562,9 @@ module Mongoid
|
|
|
562
562
|
#
|
|
563
563
|
# @since 1.0.0
|
|
564
564
|
def where(criterion = nil)
|
|
565
|
+
# We need to save the criterion in an instance variable so Modifiable methods
|
|
566
|
+
# know how to create a polymorphic object.
|
|
567
|
+
@criterion = criterion
|
|
565
568
|
criterion.is_a?(String) ? js_query(criterion) : expr_query(criterion)
|
|
566
569
|
end
|
|
567
570
|
|
|
@@ -627,8 +630,6 @@ module Mongoid
|
|
|
627
630
|
# Take the provided criterion and store it as a selection in the query
|
|
628
631
|
# selector.
|
|
629
632
|
#
|
|
630
|
-
# @api private
|
|
631
|
-
#
|
|
632
633
|
# @example Store the selection.
|
|
633
634
|
# selectable.selection({ field: "value" })
|
|
634
635
|
#
|
|
@@ -637,6 +638,7 @@ module Mongoid
|
|
|
637
638
|
# @return [ Selectable ] The cloned selectable.
|
|
638
639
|
#
|
|
639
640
|
# @since 1.0.0
|
|
641
|
+
# @api private
|
|
640
642
|
def selection(criterion = nil)
|
|
641
643
|
clone.tap do |query|
|
|
642
644
|
if criterion
|
|
@@ -21,9 +21,10 @@ module Mongoid
|
|
|
21
21
|
other.each_pair do |key, value|
|
|
22
22
|
if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
|
|
23
23
|
value = self[key.to_s].merge(value) do |_key, old_val, new_val|
|
|
24
|
-
|
|
24
|
+
case _key
|
|
25
|
+
when '$in'
|
|
25
26
|
new_val & old_val
|
|
26
|
-
|
|
27
|
+
when '$nin'
|
|
27
28
|
(old_val + new_val).uniq
|
|
28
29
|
else
|
|
29
30
|
new_val
|
|
@@ -52,10 +53,13 @@ module Mongoid
|
|
|
52
53
|
def store(key, value)
|
|
53
54
|
name, serializer = storage_pair(key)
|
|
54
55
|
if multi_selection?(name)
|
|
55
|
-
|
|
56
|
+
store_name = name
|
|
57
|
+
store_value = evolve_multi(value)
|
|
56
58
|
else
|
|
57
|
-
|
|
59
|
+
store_name = localized_key(name, serializer)
|
|
60
|
+
store_value = evolve(serializer, value)
|
|
58
61
|
end
|
|
62
|
+
super(store_name, store_value)
|
|
59
63
|
end
|
|
60
64
|
alias :[]= :store
|
|
61
65
|
|
|
@@ -178,33 +182,7 @@ module Mongoid
|
|
|
178
182
|
#
|
|
179
183
|
# @since 1.0.0
|
|
180
184
|
def multi_selection?(key)
|
|
181
|
-
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
# Determines if the selection operator takes a list. Returns true for $in and $nin.
|
|
185
|
-
#
|
|
186
|
-
# @api private
|
|
187
|
-
#
|
|
188
|
-
# @example Does the selection operator take multiple values?
|
|
189
|
-
# selector.multi_value?("$nin")
|
|
190
|
-
#
|
|
191
|
-
# @param [ String ] key The key to check.
|
|
192
|
-
#
|
|
193
|
-
# @return [ true, false ] If the key is $in or $nin.
|
|
194
|
-
#
|
|
195
|
-
# @since 2.1.1
|
|
196
|
-
def multi_value?(key)
|
|
197
|
-
key =~ /\$nin|\$in/
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
private
|
|
201
|
-
|
|
202
|
-
def in?(key)
|
|
203
|
-
key =~ /\$in/
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def nin?(key)
|
|
207
|
-
key =~ /\$nin/
|
|
185
|
+
%w($and $or $nor).include?(key)
|
|
208
186
|
end
|
|
209
187
|
end
|
|
210
188
|
end
|
data/lib/mongoid/criteria.rb
CHANGED
|
@@ -27,8 +27,8 @@ module Mongoid
|
|
|
27
27
|
include Modifiable
|
|
28
28
|
include Scopable
|
|
29
29
|
include Clients::Options
|
|
30
|
-
include Options
|
|
31
30
|
include Clients::Sessions
|
|
31
|
+
include Options
|
|
32
32
|
|
|
33
33
|
# Static array used to check with method missing - we only need to ever
|
|
34
34
|
# instantiate once.
|
|
@@ -36,7 +36,7 @@ module Mongoid
|
|
|
36
36
|
# @since 4.0.0
|
|
37
37
|
CHECK = []
|
|
38
38
|
|
|
39
|
-
attr_accessor :embedded, :klass, :parent_document, :
|
|
39
|
+
attr_accessor :embedded, :klass, :parent_document, :association
|
|
40
40
|
|
|
41
41
|
# Returns true if the supplied +Enumerable+ or +Criteria+ is equal to the results
|
|
42
42
|
# of this +Criteria+ or the criteria itself.
|
|
@@ -435,7 +435,13 @@ module Mongoid
|
|
|
435
435
|
#
|
|
436
436
|
# @since 3.1.0
|
|
437
437
|
def for_js(javascript, scope = {})
|
|
438
|
-
|
|
438
|
+
code = if scope.empty?
|
|
439
|
+
# CodeWithScope is not supported for $where as of MongoDB 4.4
|
|
440
|
+
BSON::Code.new(javascript)
|
|
441
|
+
else
|
|
442
|
+
BSON::CodeWithScope.new(javascript, scope)
|
|
443
|
+
end
|
|
444
|
+
js_query(code)
|
|
439
445
|
end
|
|
440
446
|
|
|
441
447
|
private
|
data/lib/mongoid/document.rb
CHANGED
|
@@ -4,7 +4,6 @@ require "mongoid/evolvable"
|
|
|
4
4
|
require "mongoid/extensions"
|
|
5
5
|
require "mongoid/errors"
|
|
6
6
|
require "mongoid/threaded"
|
|
7
|
-
require "mongoid/relations"
|
|
8
7
|
require "mongoid/atomic"
|
|
9
8
|
require "mongoid/attributes"
|
|
10
9
|
require "mongoid/contextual"
|
|
@@ -14,7 +13,9 @@ require "mongoid/criteria"
|
|
|
14
13
|
require "mongoid/factory"
|
|
15
14
|
require "mongoid/fields"
|
|
16
15
|
require "mongoid/timestamps"
|
|
16
|
+
require "mongoid/association"
|
|
17
17
|
require "mongoid/composable"
|
|
18
|
+
require "mongoid/touchable"
|
|
18
19
|
|
|
19
20
|
module Mongoid
|
|
20
21
|
|
|
@@ -23,6 +24,7 @@ module Mongoid
|
|
|
23
24
|
module Document
|
|
24
25
|
extend ActiveSupport::Concern
|
|
25
26
|
include Composable
|
|
27
|
+
include Mongoid::Touchable::InstanceMethods
|
|
26
28
|
|
|
27
29
|
attr_accessor :__selected_fields
|
|
28
30
|
attr_reader :new_record
|
|
@@ -178,6 +180,13 @@ module Mongoid
|
|
|
178
180
|
|
|
179
181
|
# Calls #as_json on the document with additional, Mongoid-specific options.
|
|
180
182
|
#
|
|
183
|
+
# @note Rails 6 changes return value of as_json for non-primitive types
|
|
184
|
+
# such as BSON::ObjectId. In Rails <= 5, as_json returned these as
|
|
185
|
+
# instances of the class. In Rails 6, these are returned serialized to
|
|
186
|
+
# primitive types (e.g. {"$oid"=>"5bcfc40bde340b37feda98e9"}).
|
|
187
|
+
# See https://github.com/rails/rails/commit/2e5cb980a448e7f4ab00df6e9ad4c1cc456616aa
|
|
188
|
+
# for more information.
|
|
189
|
+
#
|
|
181
190
|
# @example Get the document as json.
|
|
182
191
|
# document.as_json(compact: true)
|
|
183
192
|
#
|
|
@@ -218,8 +227,9 @@ module Mongoid
|
|
|
218
227
|
became = klass.new(clone_document)
|
|
219
228
|
became._id = _id
|
|
220
229
|
became.instance_variable_set(:@changed_attributes, changed_attributes)
|
|
221
|
-
|
|
222
|
-
|
|
230
|
+
new_errors = ActiveModel::Errors.new(became)
|
|
231
|
+
new_errors.copy!(errors)
|
|
232
|
+
became.instance_variable_set(:@errors, new_errors)
|
|
223
233
|
became.instance_variable_set(:@new_record, new_record?)
|
|
224
234
|
became.instance_variable_set(:@destroyed, destroyed?)
|
|
225
235
|
became.changed_attributes["_type"] = self.class.to_s
|
|
@@ -281,7 +291,7 @@ module Mongoid
|
|
|
281
291
|
without_autobuild do
|
|
282
292
|
relation, stored = send(name), meta.store_as
|
|
283
293
|
if attributes.key?(stored) || !relation.blank?
|
|
284
|
-
if relation
|
|
294
|
+
if !relation.nil?
|
|
285
295
|
attributes[stored] = relation.send(:as_attributes)
|
|
286
296
|
else
|
|
287
297
|
attributes.delete(stored)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module Mongoid
|
|
3
|
+
module Errors
|
|
4
|
+
|
|
5
|
+
# This error is raised when an invalid strategy is defined for an association dependency.
|
|
6
|
+
class InvalidDependentStrategy < MongoidError
|
|
7
|
+
|
|
8
|
+
# Create the new error.
|
|
9
|
+
#
|
|
10
|
+
# @example Create the new error.
|
|
11
|
+
# InvalidDependentStrategy.new(association, invalid_strategy, valid_strategies)
|
|
12
|
+
#
|
|
13
|
+
# @param [ Mongoid::Association ] association The association for which this
|
|
14
|
+
# dependency is defined.
|
|
15
|
+
# @param [ Symbol, String ] invalid_strategy The attempted invalid strategy.
|
|
16
|
+
# @param [ Array<Symbol> ] valid_strategies The valid strategies.
|
|
17
|
+
#
|
|
18
|
+
# @since 7.0.0
|
|
19
|
+
def initialize(association, invalid_strategy, valid_strategies)
|
|
20
|
+
super(
|
|
21
|
+
compose_message(
|
|
22
|
+
"invalid_dependent_strategy",
|
|
23
|
+
{ association: association,
|
|
24
|
+
invalid_strategy: invalid_strategy,
|
|
25
|
+
valid_strategies: valid_strategies
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|