activerecord 6.1.7 → 7.1.0
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
- data/CHANGELOG.md +1516 -1019
- data/MIT-LICENSE +1 -1
- data/README.rdoc +17 -18
- data/lib/active_record/aggregations.rb +17 -14
- data/lib/active_record/association_relation.rb +1 -11
- data/lib/active_record/associations/association.rb +50 -19
- data/lib/active_record/associations/association_scope.rb +17 -12
- data/lib/active_record/associations/belongs_to_association.rb +28 -9
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +11 -5
- data/lib/active_record/associations/builder/belongs_to.rb +40 -14
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -5
- data/lib/active_record/associations/builder/has_many.rb +3 -2
- data/lib/active_record/associations/builder/has_one.rb +2 -1
- data/lib/active_record/associations/builder/singular_association.rb +6 -2
- data/lib/active_record/associations/collection_association.rb +35 -31
- data/lib/active_record/associations/collection_proxy.rb +30 -15
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/foreign_association.rb +10 -3
- data/lib/active_record/associations/has_many_association.rb +28 -18
- data/lib/active_record/associations/has_many_through_association.rb +12 -7
- data/lib/active_record/associations/has_one_association.rb +20 -10
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +26 -16
- data/lib/active_record/associations/preloader/association.rb +207 -52
- data/lib/active_record/associations/preloader/batch.rb +48 -0
- data/lib/active_record/associations/preloader/branch.rb +147 -0
- data/lib/active_record/associations/preloader/through_association.rb +50 -14
- data/lib/active_record/associations/preloader.rb +50 -121
- data/lib/active_record/associations/singular_association.rb +9 -3
- data/lib/active_record/associations/through_association.rb +25 -14
- data/lib/active_record/associations.rb +423 -289
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +1 -3
- data/lib/active_record/attribute_methods/before_type_cast.rb +24 -2
- data/lib/active_record/attribute_methods/dirty.rb +61 -14
- data/lib/active_record/attribute_methods/primary_key.rb +78 -26
- data/lib/active_record/attribute_methods/query.rb +31 -19
- data/lib/active_record/attribute_methods/read.rb +25 -10
- data/lib/active_record/attribute_methods/serialization.rb +194 -37
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
- data/lib/active_record/attribute_methods/write.rb +10 -13
- data/lib/active_record/attribute_methods.rb +121 -40
- data/lib/active_record/attributes.rb +27 -38
- data/lib/active_record/autosave_association.rb +61 -30
- data/lib/active_record/base.rb +25 -2
- data/lib/active_record/callbacks.rb +18 -34
- data/lib/active_record/coders/column_serializer.rb +61 -0
- data/lib/active_record/coders/json.rb +1 -1
- data/lib/active_record/coders/yaml_column.rb +70 -46
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +367 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +211 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +78 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +96 -590
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +171 -51
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +77 -27
- data/lib/active_record/connection_adapters/abstract/quoting.rb +87 -73
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +21 -20
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +186 -31
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +360 -136
- data/lib/active_record/connection_adapters/abstract/transaction.rb +281 -59
- data/lib/active_record/connection_adapters/abstract_adapter.rb +622 -149
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +285 -156
- data/lib/active_record/connection_adapters/column.rb +13 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +25 -134
- data/lib/active_record/connection_adapters/mysql/quoting.rb +56 -25
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +9 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +10 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +38 -14
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +148 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +104 -53
- data/lib/active_record/connection_adapters/pool_config.rb +20 -11
- data/lib/active_record/connection_adapters/pool_manager.rb +19 -9
- data/lib/active_record/connection_adapters/postgresql/column.rb +18 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +86 -52
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +12 -3
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +89 -56
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +92 -2
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +153 -3
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +381 -69
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +492 -230
- data/lib/active_record/connection_adapters/schema_cache.rb +319 -90
- data/lib/active_record/connection_adapters/sqlite3/column.rb +49 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +65 -53
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +37 -21
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +7 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +43 -22
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +294 -102
- data/lib/active_record/connection_adapters/statement_pool.rb +7 -0
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +98 -0
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +254 -0
- data/lib/active_record/connection_adapters.rb +9 -6
- data/lib/active_record/connection_handling.rb +107 -136
- data/lib/active_record/core.rb +194 -224
- data/lib/active_record/counter_cache.rb +46 -25
- data/lib/active_record/database_configurations/connection_url_resolver.rb +2 -1
- data/lib/active_record/database_configurations/database_config.rb +21 -12
- data/lib/active_record/database_configurations/hash_config.rb +84 -16
- data/lib/active_record/database_configurations/url_config.rb +18 -12
- data/lib/active_record/database_configurations.rb +95 -59
- data/lib/active_record/delegated_type.rb +61 -15
- data/lib/active_record/deprecator.rb +7 -0
- data/lib/active_record/destroy_association_async_job.rb +3 -1
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
- data/lib/active_record/encryption/cipher/aes256_gcm.rb +101 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +68 -0
- data/lib/active_record/encryption/configurable.rb +60 -0
- data/lib/active_record/encryption/context.rb +42 -0
- data/lib/active_record/encryption/contexts.rb +76 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +18 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +224 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +151 -0
- data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
- data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
- data/lib/active_record/encryption/encryptor.rb +155 -0
- data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
- data/lib/active_record/encryption/errors.rb +15 -0
- data/lib/active_record/encryption/extended_deterministic_queries.rb +172 -0
- data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
- data/lib/active_record/encryption/key.rb +28 -0
- data/lib/active_record/encryption/key_generator.rb +53 -0
- data/lib/active_record/encryption/key_provider.rb +46 -0
- data/lib/active_record/encryption/message.rb +33 -0
- data/lib/active_record/encryption/message_serializer.rb +92 -0
- data/lib/active_record/encryption/null_encryptor.rb +21 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
- data/lib/active_record/encryption/scheme.rb +96 -0
- data/lib/active_record/encryption.rb +56 -0
- data/lib/active_record/enum.rb +156 -62
- data/lib/active_record/errors.rb +171 -15
- data/lib/active_record/explain.rb +23 -3
- data/lib/active_record/explain_registry.rb +11 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +15 -1
- data/lib/active_record/fixture_set/model_metadata.rb +14 -4
- data/lib/active_record/fixture_set/render_context.rb +2 -0
- data/lib/active_record/fixture_set/table_row.rb +70 -14
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +131 -86
- data/lib/active_record/future_result.rb +164 -0
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +81 -29
- data/lib/active_record/insert_all.rb +133 -20
- data/lib/active_record/integration.rb +11 -10
- data/lib/active_record/internal_metadata.rb +117 -33
- data/lib/active_record/legacy_yaml_adapter.rb +2 -39
- data/lib/active_record/locking/optimistic.rb +36 -21
- data/lib/active_record/locking/pessimistic.rb +15 -6
- data/lib/active_record/log_subscriber.rb +52 -19
- data/lib/active_record/marshalling.rb +56 -0
- data/lib/active_record/message_pack.rb +124 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +10 -10
- data/lib/active_record/middleware/database_selector.rb +23 -13
- data/lib/active_record/middleware/shard_selector.rb +62 -0
- data/lib/active_record/migration/command_recorder.rb +108 -13
- data/lib/active_record/migration/compatibility.rb +221 -48
- data/lib/active_record/migration/default_strategy.rb +23 -0
- data/lib/active_record/migration/execution_strategy.rb +19 -0
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +355 -171
- data/lib/active_record/model_schema.rb +116 -97
- data/lib/active_record/nested_attributes.rb +36 -15
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/normalization.rb +159 -0
- data/lib/active_record/persistence.rb +405 -85
- data/lib/active_record/promise.rb +84 -0
- data/lib/active_record/query_cache.rb +3 -21
- data/lib/active_record/query_logs.rb +174 -0
- data/lib/active_record/query_logs_formatter.rb +41 -0
- data/lib/active_record/querying.rb +29 -6
- data/lib/active_record/railtie.rb +219 -43
- data/lib/active_record/railties/controller_runtime.rb +13 -9
- data/lib/active_record/railties/databases.rake +185 -249
- data/lib/active_record/railties/job_runtime.rb +23 -0
- data/lib/active_record/readonly_attributes.rb +41 -3
- data/lib/active_record/reflection.rb +229 -80
- data/lib/active_record/relation/batches/batch_enumerator.rb +23 -7
- data/lib/active_record/relation/batches.rb +192 -63
- data/lib/active_record/relation/calculations.rb +211 -90
- data/lib/active_record/relation/delegation.rb +27 -13
- data/lib/active_record/relation/finder_methods.rb +108 -51
- data/lib/active_record/relation/merger.rb +22 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +31 -3
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +4 -6
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
- data/lib/active_record/relation/predicate_builder.rb +27 -20
- data/lib/active_record/relation/query_attribute.rb +30 -12
- data/lib/active_record/relation/query_methods.rb +654 -127
- data/lib/active_record/relation/record_fetch_warning.rb +7 -9
- data/lib/active_record/relation/spawn_methods.rb +20 -3
- data/lib/active_record/relation/where_clause.rb +10 -19
- data/lib/active_record/relation.rb +262 -120
- data/lib/active_record/result.rb +37 -11
- data/lib/active_record/runtime_registry.rb +18 -13
- data/lib/active_record/sanitization.rb +65 -20
- data/lib/active_record/schema.rb +36 -22
- data/lib/active_record/schema_dumper.rb +73 -24
- data/lib/active_record/schema_migration.rb +68 -33
- data/lib/active_record/scoping/default.rb +72 -15
- data/lib/active_record/scoping/named.rb +5 -13
- data/lib/active_record/scoping.rb +65 -34
- data/lib/active_record/secure_password.rb +60 -0
- data/lib/active_record/secure_token.rb +21 -3
- data/lib/active_record/serialization.rb +6 -1
- data/lib/active_record/signed_id.rb +10 -8
- data/lib/active_record/store.rb +10 -10
- data/lib/active_record/suppressor.rb +13 -15
- data/lib/active_record/table_metadata.rb +16 -3
- data/lib/active_record/tasks/database_tasks.rb +225 -136
- data/lib/active_record/tasks/mysql_database_tasks.rb +16 -7
- data/lib/active_record/tasks/postgresql_database_tasks.rb +35 -26
- data/lib/active_record/tasks/sqlite_database_tasks.rb +15 -7
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +116 -96
- data/lib/active_record/timestamp.rb +28 -17
- data/lib/active_record/token_for.rb +113 -0
- data/lib/active_record/touch_later.rb +11 -6
- data/lib/active_record/transactions.rb +48 -27
- data/lib/active_record/translation.rb +3 -3
- data/lib/active_record/type/adapter_specific_registry.rb +32 -14
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +7 -2
- data/lib/active_record/type/serialized.rb +9 -5
- data/lib/active_record/type/time.rb +4 -0
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/validations/absence.rb +1 -1
- data/lib/active_record/validations/associated.rb +4 -4
- data/lib/active_record/validations/numericality.rb +5 -4
- data/lib/active_record/validations/presence.rb +5 -28
- data/lib/active_record/validations/uniqueness.rb +51 -6
- data/lib/active_record/validations.rb +8 -4
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +335 -32
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/crud.rb +28 -22
- data/lib/arel/delete_manager.rb +18 -4
- data/lib/arel/errors.rb +10 -0
- data/lib/arel/factory_methods.rb +4 -0
- data/lib/arel/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/and.rb +4 -0
- data/lib/arel/nodes/binary.rb +6 -1
- data/lib/arel/nodes/bound_sql_literal.rb +61 -0
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/cte.rb +36 -0
- data/lib/arel/nodes/delete_statement.rb +12 -13
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/fragments.rb +35 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/homogeneous_in.rb +0 -8
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/leading_join.rb +8 -0
- data/lib/arel/nodes/node.rb +111 -2
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/sql_literal.rb +6 -0
- data/lib/arel/nodes/table_alias.rb +4 -0
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +5 -0
- data/lib/arel/predications.rb +13 -3
- data/lib/arel/select_manager.rb +10 -4
- data/lib/arel/table.rb +9 -6
- data/lib/arel/tree_manager.rb +0 -12
- data/lib/arel/update_manager.rb +18 -4
- data/lib/arel/visitors/dot.rb +80 -90
- data/lib/arel/visitors/mysql.rb +16 -3
- data/lib/arel/visitors/postgresql.rb +0 -10
- data/lib/arel/visitors/to_sql.rb +139 -19
- data/lib/arel/visitors/visitor.rb +2 -2
- data/lib/arel.rb +18 -3
- data/lib/rails/generators/active_record/application_record/USAGE +8 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration.rb +3 -1
- data/lib/rails/generators/active_record/model/USAGE +113 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
- data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
- data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
- metadata +92 -13
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
- data/lib/active_record/null_relation.rb +0 -67
@@ -21,10 +21,11 @@ module ActiveRecord
|
|
21
21
|
|
22
22
|
module ClassMethods
|
23
23
|
# Validates whether the value of the specified attribute is numeric by
|
24
|
-
# trying to convert it to a float with Kernel.Float (if
|
25
|
-
# is +false+) or applying it to the regular
|
26
|
-
# (if <tt>only_integer</tt> is set to
|
27
|
-
# defaults to the column's precision
|
24
|
+
# trying to convert it to a float with +Kernel.Float+ (if
|
25
|
+
# <tt>only_integer</tt> is +false+) or applying it to the regular
|
26
|
+
# expression <tt>/\A[\+\-]?\d+\z/</tt> (if <tt>only_integer</tt> is set to
|
27
|
+
# +true+). +Kernel.Float+ precision defaults to the column's precision
|
28
|
+
# value or 15.
|
28
29
|
#
|
29
30
|
# See ActiveModel::Validations::HelperMethods.validates_numericality_of for more information.
|
30
31
|
def validates_numericality_of(*attr_names)
|
@@ -13,9 +13,8 @@ module ActiveRecord
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
15
|
# Validates that the specified attributes are not blank (as defined by
|
16
|
-
# Object#blank?)
|
17
|
-
#
|
18
|
-
# on save.
|
16
|
+
# Object#blank?). If the attribute is an association, the associated object
|
17
|
+
# is also considered blank if it is marked for destruction.
|
19
18
|
#
|
20
19
|
# class Person < ActiveRecord::Base
|
21
20
|
# has_one :face
|
@@ -25,41 +24,19 @@ module ActiveRecord
|
|
25
24
|
# The face attribute must be in the object and it cannot be blank or marked
|
26
25
|
# for destruction.
|
27
26
|
#
|
28
|
-
# If you want to validate the presence of a boolean field (where the real values
|
29
|
-
# are true and false), you will want to use
|
30
|
-
# <tt>validates_inclusion_of :field_name, in: [true, false]</tt>.
|
31
|
-
#
|
32
|
-
# This is due to the way Object#blank? handles boolean values:
|
33
|
-
# <tt>false.blank? # => true</tt>.
|
34
|
-
#
|
35
27
|
# This validator defers to the Active Model validation for presence, adding the
|
36
28
|
# check to see that an associated object is not marked for destruction. This
|
37
29
|
# prevents the parent object from validating successfully and saving, which then
|
38
30
|
# deletes the associated object, thus putting the parent object into an invalid
|
39
31
|
# state.
|
40
32
|
#
|
33
|
+
# See ActiveModel::Validations::HelperMethods.validates_presence_of for
|
34
|
+
# more information.
|
35
|
+
#
|
41
36
|
# NOTE: This validation will not fail while using it with an association
|
42
37
|
# if the latter was assigned but not valid. If you want to ensure that
|
43
38
|
# it is both present and valid, you also need to use
|
44
39
|
# {validates_associated}[rdoc-ref:Validations::ClassMethods#validates_associated].
|
45
|
-
#
|
46
|
-
# Configuration options:
|
47
|
-
# * <tt>:message</tt> - A custom error message (default is: "can't be blank").
|
48
|
-
# * <tt>:on</tt> - Specifies the contexts where this validation is active.
|
49
|
-
# Runs in all validation contexts by default +nil+. You can pass a symbol
|
50
|
-
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
51
|
-
# <tt>on: :custom_validation_context</tt> or
|
52
|
-
# <tt>on: [:create, :custom_validation_context]</tt>)
|
53
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
|
54
|
-
# the validation should occur (e.g. <tt>if: :allow_validation</tt>, or
|
55
|
-
# <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method, proc
|
56
|
-
# or string should return or evaluate to a +true+ or +false+ value.
|
57
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
|
58
|
-
# if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
59
|
-
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
|
60
|
-
# proc or string should return or evaluate to a +true+ or +false+ value.
|
61
|
-
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
62
|
-
# See ActiveModel::Validations#validates! for more information.
|
63
40
|
def validates_presence_of(*attr_names)
|
64
41
|
validates_with PresenceValidator, _merge_attributes(attr_names)
|
65
42
|
end
|
@@ -20,10 +20,12 @@ module ActiveRecord
|
|
20
20
|
finder_class = find_finder_class_for(record)
|
21
21
|
value = map_enum_attribute(finder_class, attribute, value)
|
22
22
|
|
23
|
+
return if record.persisted? && !validation_needed?(finder_class, record, attribute)
|
24
|
+
|
23
25
|
relation = build_relation(finder_class, attribute, value)
|
24
26
|
if record.persisted?
|
25
27
|
if finder_class.primary_key
|
26
|
-
relation = relation.where.not(finder_class.primary_key => record.id_in_database)
|
28
|
+
relation = relation.where.not(finder_class.primary_key => [record.id_in_database])
|
27
29
|
else
|
28
30
|
raise UnknownPrimaryKey.new(finder_class, "Cannot validate uniqueness for persisted record without primary key.")
|
29
31
|
end
|
@@ -64,6 +66,48 @@ module ActiveRecord
|
|
64
66
|
class_hierarchy.detect { |klass| !klass.abstract_class? }
|
65
67
|
end
|
66
68
|
|
69
|
+
def validation_needed?(klass, record, attribute)
|
70
|
+
return true if options[:conditions] || options.key?(:case_sensitive)
|
71
|
+
|
72
|
+
scope = Array(options[:scope])
|
73
|
+
attributes = scope + [attribute]
|
74
|
+
attributes = resolve_attributes(record, attributes)
|
75
|
+
|
76
|
+
return true if attributes.any? { |attr| record.attribute_changed?(attr) ||
|
77
|
+
record.read_attribute(attr).nil? }
|
78
|
+
|
79
|
+
!covered_by_unique_index?(klass, record, attribute, scope)
|
80
|
+
end
|
81
|
+
|
82
|
+
def covered_by_unique_index?(klass, record, attribute, scope)
|
83
|
+
@covered ||= self.attributes.map(&:to_s).select do |attr|
|
84
|
+
attributes = scope + [attr]
|
85
|
+
attributes = resolve_attributes(record, attributes)
|
86
|
+
|
87
|
+
klass.connection.schema_cache.indexes(klass.table_name).any? do |index|
|
88
|
+
index.unique &&
|
89
|
+
index.where.nil? &&
|
90
|
+
(Array(index.columns) - attributes).empty?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
@covered.include?(attribute.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
def resolve_attributes(record, attributes)
|
98
|
+
attributes.flat_map do |attribute|
|
99
|
+
reflection = record.class._reflect_on_association(attribute)
|
100
|
+
|
101
|
+
if reflection.nil?
|
102
|
+
attribute.to_s
|
103
|
+
elsif reflection.polymorphic?
|
104
|
+
[reflection.foreign_key, reflection.foreign_type]
|
105
|
+
else
|
106
|
+
reflection.foreign_key
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
67
111
|
def build_relation(klass, attribute, value)
|
68
112
|
relation = klass.unscoped
|
69
113
|
comparison = relation.bind_attribute(attribute, value) do |attr, bind|
|
@@ -161,19 +205,19 @@ module ActiveRecord
|
|
161
205
|
# <tt>WHERE</tt> SQL fragment to limit the uniqueness constraint lookup
|
162
206
|
# (e.g. <tt>conditions: -> { where(status: 'active') }</tt>).
|
163
207
|
# * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by
|
164
|
-
# non-text columns
|
208
|
+
# non-text columns. The default behavior respects the default database collation.
|
165
209
|
# * <tt>:allow_nil</tt> - If set to +true+, skips this validation if the
|
166
210
|
# attribute is +nil+ (default is +false+).
|
167
211
|
# * <tt>:allow_blank</tt> - If set to +true+, skips this validation if the
|
168
212
|
# attribute is blank (default is +false+).
|
169
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
213
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
170
214
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
171
215
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
172
216
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
173
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
217
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to
|
174
218
|
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
175
219
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
176
|
-
# method, proc or string should return or evaluate to a +true+ or +false+
|
220
|
+
# method, proc, or string should return or evaluate to a +true+ or +false+
|
177
221
|
# value.
|
178
222
|
#
|
179
223
|
# === Concurrency and integrity
|
@@ -221,7 +265,7 @@ module ActiveRecord
|
|
221
265
|
# When the database catches such a duplicate insertion,
|
222
266
|
# {ActiveRecord::Base#save}[rdoc-ref:Persistence#save] will raise an ActiveRecord::StatementInvalid
|
223
267
|
# exception. You can either choose to let this error propagate (which
|
224
|
-
# will result in the default Rails exception page being shown), or you
|
268
|
+
# will result in the default \Rails exception page being shown), or you
|
225
269
|
# can catch it and restart the transaction (e.g. by telling the user
|
226
270
|
# that the title already exists, and asking them to re-enter the title).
|
227
271
|
# This technique is also known as
|
@@ -236,6 +280,7 @@ module ActiveRecord
|
|
236
280
|
# The following bundled adapters throw the ActiveRecord::RecordNotUnique exception:
|
237
281
|
#
|
238
282
|
# * ActiveRecord::ConnectionAdapters::Mysql2Adapter.
|
283
|
+
# * ActiveRecord::ConnectionAdapters::TrilogyAdapter.
|
239
284
|
# * ActiveRecord::ConnectionAdapters::SQLite3Adapter.
|
240
285
|
# * ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.
|
241
286
|
def validates_uniqueness_of(*attr_names)
|
@@ -30,10 +30,12 @@ module ActiveRecord
|
|
30
30
|
|
31
31
|
# = Active Record \Validations
|
32
32
|
#
|
33
|
-
# Active Record includes the majority of its validations from ActiveModel::Validations
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
33
|
+
# Active Record includes the majority of its validations from ActiveModel::Validations.
|
34
|
+
#
|
35
|
+
# In Active Record, all validations are performed on save by default.
|
36
|
+
# Validations accept the <tt>:on</tt> argument to define the context where
|
37
|
+
# the validations are active. Active Record will pass either the context of
|
38
|
+
# <tt>:create</tt> or <tt>:update</tt> depending on whether the model is a
|
37
39
|
# {new_record?}[rdoc-ref:Persistence#new_record?].
|
38
40
|
module Validations
|
39
41
|
extend ActiveSupport::Concern
|
@@ -60,6 +62,8 @@ module ActiveRecord
|
|
60
62
|
#
|
61
63
|
# If the argument is +false+ (default is +nil+), the context is set to <tt>:create</tt> if
|
62
64
|
# {new_record?}[rdoc-ref:Persistence#new_record?] is +true+, and to <tt>:update</tt> if it is not.
|
65
|
+
# If the argument is an array of contexts, <tt>post.valid?([:create, :update])</tt>, the validations are
|
66
|
+
# run within multiple contexts.
|
63
67
|
#
|
64
68
|
# \Validations with no <tt>:on</tt> option will run no matter the context. \Validations with
|
65
69
|
# some <tt>:on</tt> option will only run in the specified context.
|
data/lib/active_record.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c)
|
4
|
+
# Copyright (c) David Heinemeier Hansson
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
# a copy of this software and associated documentation files (the
|
@@ -30,32 +30,40 @@ require "arel"
|
|
30
30
|
require "yaml"
|
31
31
|
|
32
32
|
require "active_record/version"
|
33
|
+
require "active_record/deprecator"
|
33
34
|
require "active_model/attribute_set"
|
34
35
|
require "active_record/errors"
|
35
36
|
|
37
|
+
# :include: activerecord/README.rdoc
|
36
38
|
module ActiveRecord
|
37
39
|
extend ActiveSupport::Autoload
|
38
40
|
|
39
41
|
autoload :Base
|
40
42
|
autoload :Callbacks
|
41
|
-
autoload :Core
|
42
43
|
autoload :ConnectionHandling
|
44
|
+
autoload :Core
|
43
45
|
autoload :CounterCache
|
44
|
-
autoload :DynamicMatchers
|
45
46
|
autoload :DelegatedType
|
47
|
+
autoload :DestroyAssociationAsyncJob
|
48
|
+
autoload :DynamicMatchers
|
49
|
+
autoload :Encryption
|
46
50
|
autoload :Enum
|
47
|
-
autoload :InternalMetadata
|
48
51
|
autoload :Explain
|
52
|
+
autoload :FixtureSet, "active_record/fixtures"
|
49
53
|
autoload :Inheritance
|
50
54
|
autoload :Integration
|
55
|
+
autoload :InternalMetadata
|
56
|
+
autoload :LogSubscriber
|
57
|
+
autoload :Marshalling
|
51
58
|
autoload :Migration
|
52
59
|
autoload :Migrator, "active_record/migration"
|
53
60
|
autoload :ModelSchema
|
54
61
|
autoload :NestedAttributes
|
55
62
|
autoload :NoTouching
|
56
|
-
autoload :
|
63
|
+
autoload :Normalization
|
57
64
|
autoload :Persistence
|
58
65
|
autoload :QueryCache
|
66
|
+
autoload :QueryLogs
|
59
67
|
autoload :Querying
|
60
68
|
autoload :ReadonlyAttributes
|
61
69
|
autoload :RecordInvalid, "active_record/validations"
|
@@ -66,51 +74,55 @@ module ActiveRecord
|
|
66
74
|
autoload :SchemaDumper
|
67
75
|
autoload :SchemaMigration
|
68
76
|
autoload :Scoping
|
77
|
+
autoload :SecurePassword
|
78
|
+
autoload :SecureToken
|
69
79
|
autoload :Serialization
|
70
|
-
autoload :StatementCache
|
71
|
-
autoload :Store
|
72
80
|
autoload :SignedId
|
81
|
+
autoload :Store
|
73
82
|
autoload :Suppressor
|
83
|
+
autoload :TestDatabases
|
84
|
+
autoload :TestFixtures, "active_record/fixtures"
|
74
85
|
autoload :Timestamp
|
86
|
+
autoload :TokenFor
|
87
|
+
autoload :TouchLater
|
75
88
|
autoload :Transactions
|
76
89
|
autoload :Translation
|
77
90
|
autoload :Validations
|
78
|
-
autoload :SecureToken
|
79
|
-
autoload :DestroyAssociationAsyncJob
|
80
91
|
|
81
92
|
eager_autoload do
|
82
|
-
autoload :ConnectionAdapters
|
83
|
-
|
84
93
|
autoload :Aggregations
|
94
|
+
autoload :AssociationRelation
|
85
95
|
autoload :Associations
|
96
|
+
autoload :AsynchronousQueriesTracker
|
86
97
|
autoload :AttributeAssignment
|
87
98
|
autoload :AttributeMethods
|
88
99
|
autoload :AutosaveAssociation
|
89
|
-
|
100
|
+
autoload :ConnectionAdapters
|
101
|
+
autoload :DisableJoinsAssociationRelation
|
102
|
+
autoload :FutureResult
|
90
103
|
autoload :LegacyYamlAdapter
|
91
|
-
|
104
|
+
autoload :Promise
|
92
105
|
autoload :Relation
|
93
|
-
autoload :
|
94
|
-
autoload :
|
106
|
+
autoload :Result
|
107
|
+
autoload :StatementCache
|
108
|
+
autoload :TableMetadata
|
109
|
+
autoload :Type
|
95
110
|
|
96
111
|
autoload_under "relation" do
|
97
|
-
autoload :
|
98
|
-
autoload :FinderMethods
|
112
|
+
autoload :Batches
|
99
113
|
autoload :Calculations
|
114
|
+
autoload :Delegation
|
115
|
+
autoload :FinderMethods
|
100
116
|
autoload :PredicateBuilder
|
117
|
+
autoload :QueryMethods
|
101
118
|
autoload :SpawnMethods
|
102
|
-
autoload :Batches
|
103
|
-
autoload :Delegation
|
104
119
|
end
|
105
|
-
|
106
|
-
autoload :Result
|
107
|
-
autoload :TableMetadata
|
108
|
-
autoload :Type
|
109
120
|
end
|
110
121
|
|
111
122
|
module Coders
|
112
|
-
autoload :
|
123
|
+
autoload :ColumnSerializer, "active_record/coders/column_serializer"
|
113
124
|
autoload :JSON, "active_record/coders/json"
|
125
|
+
autoload :YAMLColumn, "active_record/coders/yaml_column"
|
114
126
|
end
|
115
127
|
|
116
128
|
module AttributeMethods
|
@@ -122,9 +134,9 @@ module ActiveRecord
|
|
122
134
|
autoload :PrimaryKey
|
123
135
|
autoload :Query
|
124
136
|
autoload :Read
|
137
|
+
autoload :Serialization
|
125
138
|
autoload :TimeZoneConversion
|
126
139
|
autoload :Write
|
127
|
-
autoload :Serialization
|
128
140
|
end
|
129
141
|
end
|
130
142
|
|
@@ -141,29 +153,314 @@ module ActiveRecord
|
|
141
153
|
extend ActiveSupport::Autoload
|
142
154
|
|
143
155
|
eager_autoload do
|
144
|
-
autoload :Named
|
145
156
|
autoload :Default
|
157
|
+
autoload :Named
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
149
161
|
module Middleware
|
150
162
|
extend ActiveSupport::Autoload
|
151
163
|
|
152
|
-
autoload :DatabaseSelector
|
164
|
+
autoload :DatabaseSelector
|
165
|
+
autoload :ShardSelector
|
153
166
|
end
|
154
167
|
|
155
168
|
module Tasks
|
156
169
|
extend ActiveSupport::Autoload
|
157
170
|
|
158
171
|
autoload :DatabaseTasks
|
159
|
-
autoload :SQLiteDatabaseTasks, "active_record/tasks/sqlite_database_tasks"
|
160
172
|
autoload :MySQLDatabaseTasks, "active_record/tasks/mysql_database_tasks"
|
161
|
-
autoload :PostgreSQLDatabaseTasks,
|
162
|
-
|
173
|
+
autoload :PostgreSQLDatabaseTasks, "active_record/tasks/postgresql_database_tasks"
|
174
|
+
autoload :SQLiteDatabaseTasks, "active_record/tasks/sqlite_database_tasks"
|
163
175
|
end
|
164
176
|
|
165
|
-
|
166
|
-
|
177
|
+
singleton_class.attr_accessor :disable_prepared_statements
|
178
|
+
self.disable_prepared_statements = false
|
179
|
+
|
180
|
+
# Lazily load the schema cache. This option will load the schema cache
|
181
|
+
# when a connection is established rather than on boot. If set,
|
182
|
+
# +config.active_record.use_schema_cache_dump+ will be set to false.
|
183
|
+
singleton_class.attr_accessor :lazily_load_schema_cache
|
184
|
+
self.lazily_load_schema_cache = false
|
185
|
+
|
186
|
+
# A list of tables or regex's to match tables to ignore when
|
187
|
+
# dumping the schema cache. For example if this is set to +[/^_/]+
|
188
|
+
# the schema cache will not dump tables named with an underscore.
|
189
|
+
singleton_class.attr_accessor :schema_cache_ignored_tables
|
190
|
+
self.schema_cache_ignored_tables = []
|
191
|
+
|
192
|
+
singleton_class.attr_reader :default_timezone
|
193
|
+
|
194
|
+
# Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
|
195
|
+
# dates and times from the database. This is set to :utc by default.
|
196
|
+
def self.default_timezone=(default_timezone)
|
197
|
+
unless %i(local utc).include?(default_timezone)
|
198
|
+
raise ArgumentError, "default_timezone must be either :utc (default) or :local."
|
199
|
+
end
|
200
|
+
|
201
|
+
@default_timezone = default_timezone
|
202
|
+
end
|
203
|
+
|
204
|
+
self.default_timezone = :utc
|
205
|
+
|
206
|
+
# The action to take when database query produces warning.
|
207
|
+
# Must be one of :ignore, :log, :raise, :report, or a custom proc.
|
208
|
+
# The default is :ignore.
|
209
|
+
singleton_class.attr_reader :db_warnings_action
|
210
|
+
|
211
|
+
def self.db_warnings_action=(action)
|
212
|
+
@db_warnings_action =
|
213
|
+
case action
|
214
|
+
when :ignore
|
215
|
+
nil
|
216
|
+
when :log
|
217
|
+
->(warning) do
|
218
|
+
warning_message = "[#{warning.class}] #{warning.message}"
|
219
|
+
warning_message += " (#{warning.code})" if warning.code
|
220
|
+
ActiveRecord::Base.logger.warn(warning_message)
|
221
|
+
end
|
222
|
+
when :raise
|
223
|
+
->(warning) { raise warning }
|
224
|
+
when :report
|
225
|
+
->(warning) { Rails.error.report(warning, handled: true) }
|
226
|
+
when Proc
|
227
|
+
action
|
228
|
+
else
|
229
|
+
raise ArgumentError, "db_warnings_action must be one of :ignore, :log, :raise, :report, or a custom proc."
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
self.db_warnings_action = :ignore
|
234
|
+
|
235
|
+
# Specify allowlist of database warnings.
|
236
|
+
singleton_class.attr_accessor :db_warnings_ignore
|
237
|
+
self.db_warnings_ignore = []
|
238
|
+
|
239
|
+
singleton_class.attr_accessor :writing_role
|
240
|
+
self.writing_role = :writing
|
241
|
+
|
242
|
+
singleton_class.attr_accessor :reading_role
|
243
|
+
self.reading_role = :reading
|
244
|
+
|
245
|
+
def self.legacy_connection_handling=(_)
|
246
|
+
raise ArgumentError, <<~MSG.squish
|
247
|
+
The `legacy_connection_handling` setter was deprecated in 7.0 and removed in 7.1,
|
248
|
+
but is still defined in your configuration. Please remove this call as it no longer
|
249
|
+
has any effect."
|
250
|
+
MSG
|
251
|
+
end
|
252
|
+
|
253
|
+
# Sets the async_query_executor for an application. By default the thread pool executor
|
254
|
+
# set to +nil+ which will not run queries in the background. Applications must configure
|
255
|
+
# a thread pool executor to use this feature. Options are:
|
256
|
+
#
|
257
|
+
# * nil - Does not initialize a thread pool executor. Any async calls will be
|
258
|
+
# run in the foreground.
|
259
|
+
# * :global_thread_pool - Initializes a single +Concurrent::ThreadPoolExecutor+
|
260
|
+
# that uses the +async_query_concurrency+ for the +max_threads+ value.
|
261
|
+
# * :multi_thread_pool - Initializes a +Concurrent::ThreadPoolExecutor+ for each
|
262
|
+
# database connection. The initializer values are defined in the configuration hash.
|
263
|
+
singleton_class.attr_accessor :async_query_executor
|
264
|
+
self.async_query_executor = nil
|
265
|
+
|
266
|
+
def self.global_thread_pool_async_query_executor # :nodoc:
|
267
|
+
concurrency = global_executor_concurrency || 4
|
268
|
+
@global_thread_pool_async_query_executor ||= Concurrent::ThreadPoolExecutor.new(
|
269
|
+
min_threads: 0,
|
270
|
+
max_threads: concurrency,
|
271
|
+
max_queue: concurrency * 4,
|
272
|
+
fallback_policy: :caller_runs
|
273
|
+
)
|
274
|
+
end
|
275
|
+
|
276
|
+
# Set the +global_executor_concurrency+. This configuration value can only be used
|
277
|
+
# with the global thread pool async query executor.
|
278
|
+
def self.global_executor_concurrency=(global_executor_concurrency)
|
279
|
+
if self.async_query_executor.nil? || self.async_query_executor == :multi_thread_pool
|
280
|
+
raise ArgumentError, "`global_executor_concurrency` cannot be set when using the executor is nil or set to multi_thead_pool. For multiple thread pools, please set the concurrency in your database configuration."
|
281
|
+
end
|
282
|
+
|
283
|
+
@global_executor_concurrency = global_executor_concurrency
|
284
|
+
end
|
285
|
+
|
286
|
+
def self.global_executor_concurrency # :nodoc:
|
287
|
+
@global_executor_concurrency ||= nil
|
288
|
+
end
|
289
|
+
|
290
|
+
singleton_class.attr_accessor :index_nested_attribute_errors
|
291
|
+
self.index_nested_attribute_errors = false
|
292
|
+
|
293
|
+
##
|
294
|
+
# :singleton-method:
|
295
|
+
#
|
296
|
+
# Specifies if the methods calling database queries should be logged below
|
297
|
+
# their relevant queries. Defaults to false.
|
298
|
+
singleton_class.attr_accessor :verbose_query_logs
|
299
|
+
self.verbose_query_logs = false
|
300
|
+
|
301
|
+
##
|
302
|
+
# :singleton-method:
|
303
|
+
#
|
304
|
+
# Specifies the names of the queues used by background jobs.
|
305
|
+
singleton_class.attr_accessor :queues
|
306
|
+
self.queues = {}
|
307
|
+
|
308
|
+
singleton_class.attr_accessor :maintain_test_schema
|
309
|
+
self.maintain_test_schema = nil
|
310
|
+
|
311
|
+
singleton_class.attr_accessor :raise_on_assign_to_attr_readonly
|
312
|
+
self.raise_on_assign_to_attr_readonly = false
|
313
|
+
|
314
|
+
singleton_class.attr_accessor :belongs_to_required_validates_foreign_key
|
315
|
+
self.belongs_to_required_validates_foreign_key = true
|
316
|
+
|
317
|
+
singleton_class.attr_accessor :before_committed_on_all_records
|
318
|
+
self.before_committed_on_all_records = false
|
319
|
+
|
320
|
+
singleton_class.attr_accessor :run_after_transaction_callbacks_in_order_defined
|
321
|
+
self.run_after_transaction_callbacks_in_order_defined = false
|
322
|
+
|
323
|
+
singleton_class.attr_accessor :commit_transaction_on_non_local_return
|
324
|
+
self.commit_transaction_on_non_local_return = false
|
325
|
+
|
326
|
+
##
|
327
|
+
# :singleton-method:
|
328
|
+
# Specify a threshold for the size of query result sets. If the number of
|
329
|
+
# records in the set exceeds the threshold, a warning is logged. This can
|
330
|
+
# be used to identify queries which load thousands of records and
|
331
|
+
# potentially cause memory bloat.
|
332
|
+
singleton_class.attr_accessor :warn_on_records_fetched_greater_than
|
333
|
+
self.warn_on_records_fetched_greater_than = false
|
334
|
+
|
335
|
+
singleton_class.attr_accessor :application_record_class
|
336
|
+
self.application_record_class = nil
|
337
|
+
|
338
|
+
##
|
339
|
+
# :singleton-method:
|
340
|
+
# Set the application to log or raise when an association violates strict loading.
|
341
|
+
# Defaults to :raise.
|
342
|
+
singleton_class.attr_accessor :action_on_strict_loading_violation
|
343
|
+
self.action_on_strict_loading_violation = :raise
|
344
|
+
|
345
|
+
##
|
346
|
+
# :singleton-method:
|
347
|
+
# Specifies the format to use when dumping the database schema with Rails'
|
348
|
+
# Rakefile. If :sql, the schema is dumped as (potentially database-
|
349
|
+
# specific) SQL statements. If :ruby, the schema is dumped as an
|
350
|
+
# ActiveRecord::Schema file which can be loaded into any database that
|
351
|
+
# supports migrations. Use :ruby if you want to have different database
|
352
|
+
# adapters for, e.g., your development and test environments.
|
353
|
+
singleton_class.attr_accessor :schema_format
|
354
|
+
self.schema_format = :ruby
|
355
|
+
|
356
|
+
##
|
357
|
+
# :singleton-method:
|
358
|
+
# Specifies if an error should be raised if the query has an order being
|
359
|
+
# ignored when doing batch queries. Useful in applications where the
|
360
|
+
# scope being ignored is error-worthy, rather than a warning.
|
361
|
+
singleton_class.attr_accessor :error_on_ignored_order
|
362
|
+
self.error_on_ignored_order = false
|
363
|
+
|
364
|
+
##
|
365
|
+
# :singleton-method:
|
366
|
+
# Specify whether or not to use timestamps for migration versions
|
367
|
+
singleton_class.attr_accessor :timestamped_migrations
|
368
|
+
self.timestamped_migrations = true
|
369
|
+
|
370
|
+
##
|
371
|
+
# :singleton-method:
|
372
|
+
# Specify strategy to use for executing migrations.
|
373
|
+
singleton_class.attr_accessor :migration_strategy
|
374
|
+
self.migration_strategy = Migration::DefaultStrategy
|
375
|
+
|
376
|
+
##
|
377
|
+
# :singleton-method:
|
378
|
+
# Specify whether schema dump should happen at the end of the
|
379
|
+
# bin/rails db:migrate command. This is true by default, which is useful for the
|
380
|
+
# development environment. This should ideally be false in the production
|
381
|
+
# environment where dumping schema is rarely needed.
|
382
|
+
singleton_class.attr_accessor :dump_schema_after_migration
|
383
|
+
self.dump_schema_after_migration = true
|
384
|
+
|
385
|
+
##
|
386
|
+
# :singleton-method:
|
387
|
+
# Specifies which database schemas to dump when calling db:schema:dump.
|
388
|
+
# If the value is :schema_search_path (the default), any schemas listed in
|
389
|
+
# schema_search_path are dumped. Use :all to dump all schemas regardless
|
390
|
+
# of schema_search_path, or a string of comma separated schemas for a
|
391
|
+
# custom list.
|
392
|
+
singleton_class.attr_accessor :dump_schemas
|
393
|
+
self.dump_schemas = :schema_search_path
|
394
|
+
|
395
|
+
def self.suppress_multiple_database_warning
|
396
|
+
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
397
|
+
config.active_record.suppress_multiple_database_warning is deprecated and will be removed in Rails 7.2.
|
398
|
+
It no longer has any effect and should be removed from the configuration file.
|
399
|
+
MSG
|
400
|
+
end
|
401
|
+
|
402
|
+
def self.suppress_multiple_database_warning=(value)
|
403
|
+
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
404
|
+
config.active_record.suppress_multiple_database_warning= is deprecated and will be removed in Rails 7.2.
|
405
|
+
It no longer has any effect and should be removed from the configuration file.
|
406
|
+
MSG
|
407
|
+
end
|
408
|
+
|
409
|
+
##
|
410
|
+
# :singleton-method:
|
411
|
+
# If true, Rails will verify all foreign keys in the database after loading fixtures.
|
412
|
+
# An error will be raised if there are any foreign key violations, indicating incorrectly
|
413
|
+
# written fixtures.
|
414
|
+
# Supported by PostgreSQL and SQLite.
|
415
|
+
singleton_class.attr_accessor :verify_foreign_keys_for_fixtures
|
416
|
+
self.verify_foreign_keys_for_fixtures = false
|
417
|
+
|
418
|
+
##
|
419
|
+
# :singleton-method:
|
420
|
+
# If true, Rails will continue allowing plural association names in where clauses on singular associations
|
421
|
+
# This behavior will be removed in Rails 7.2.
|
422
|
+
singleton_class.attr_accessor :allow_deprecated_singular_associations_name
|
423
|
+
self.allow_deprecated_singular_associations_name = true
|
424
|
+
|
425
|
+
singleton_class.attr_accessor :query_transformers
|
426
|
+
self.query_transformers = []
|
427
|
+
|
428
|
+
##
|
429
|
+
# :singleton-method:
|
430
|
+
# Application configurable boolean that instructs the YAML Coder to use
|
431
|
+
# an unsafe load if set to true.
|
432
|
+
singleton_class.attr_accessor :use_yaml_unsafe_load
|
433
|
+
self.use_yaml_unsafe_load = false
|
434
|
+
|
435
|
+
##
|
436
|
+
# :singleton-method:
|
437
|
+
# Application configurable boolean that denotes whether or not to raise
|
438
|
+
# an exception when the PostgreSQLAdapter is provided with an integer that
|
439
|
+
# is wider than signed 64bit representation
|
440
|
+
singleton_class.attr_accessor :raise_int_wider_than_64bit
|
441
|
+
self.raise_int_wider_than_64bit = true
|
442
|
+
|
443
|
+
##
|
444
|
+
# :singleton-method:
|
445
|
+
# Application configurable array that provides additional permitted classes
|
446
|
+
# to Psych safe_load in the YAML Coder
|
447
|
+
singleton_class.attr_accessor :yaml_column_permitted_classes
|
448
|
+
self.yaml_column_permitted_classes = [Symbol]
|
449
|
+
|
450
|
+
##
|
451
|
+
# :singleton-method:
|
452
|
+
# Controls when to generate a value for <tt>has_secure_token</tt>
|
453
|
+
# declarations. Defaults to <tt>:create</tt>.
|
454
|
+
singleton_class.attr_accessor :generate_secure_token_on
|
455
|
+
self.generate_secure_token_on = :create
|
456
|
+
|
457
|
+
def self.marshalling_format_version
|
458
|
+
Marshalling.format_version
|
459
|
+
end
|
460
|
+
|
461
|
+
def self.marshalling_format_version=(value)
|
462
|
+
Marshalling.format_version = value
|
463
|
+
end
|
167
464
|
|
168
465
|
def self.eager_load!
|
169
466
|
super
|
@@ -172,6 +469,12 @@ module ActiveRecord
|
|
172
469
|
ActiveRecord::Associations.eager_load!
|
173
470
|
ActiveRecord::AttributeMethods.eager_load!
|
174
471
|
ActiveRecord::ConnectionAdapters.eager_load!
|
472
|
+
ActiveRecord::Encryption.eager_load!
|
473
|
+
end
|
474
|
+
|
475
|
+
# Explicitly closes all database connections in all pools.
|
476
|
+
def self.disconnect_all!
|
477
|
+
ConnectionAdapters::PoolConfig.disconnect_all!
|
175
478
|
end
|
176
479
|
end
|
177
480
|
|