activerecord 5.2.8.1 → 6.1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1347 -624
- data/MIT-LICENSE +3 -1
- data/README.rdoc +7 -5
- data/examples/performance.rb +1 -1
- data/lib/active_record/aggregations.rb +9 -8
- data/lib/active_record/association_relation.rb +30 -10
- data/lib/active_record/associations/alias_tracker.rb +19 -16
- data/lib/active_record/associations/association.rb +100 -41
- data/lib/active_record/associations/association_scope.rb +23 -21
- data/lib/active_record/associations/belongs_to_association.rb +55 -48
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -6
- data/lib/active_record/associations/builder/association.rb +45 -22
- data/lib/active_record/associations/builder/belongs_to.rb +29 -59
- data/lib/active_record/associations/builder/collection_association.rb +8 -17
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
- data/lib/active_record/associations/builder/has_many.rb +8 -2
- data/lib/active_record/associations/builder/has_one.rb +33 -2
- data/lib/active_record/associations/builder/singular_association.rb +3 -1
- data/lib/active_record/associations/collection_association.rb +44 -34
- data/lib/active_record/associations/collection_proxy.rb +25 -21
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +26 -13
- data/lib/active_record/associations/has_many_through_association.rb +24 -18
- data/lib/active_record/associations/has_one_association.rb +43 -31
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency/join_association.rb +44 -22
- data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
- data/lib/active_record/associations/join_dependency.rb +91 -60
- data/lib/active_record/associations/preloader/association.rb +69 -43
- data/lib/active_record/associations/preloader/through_association.rb +49 -40
- data/lib/active_record/associations/preloader.rb +47 -34
- data/lib/active_record/associations/singular_association.rb +3 -17
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +137 -25
- data/lib/active_record/attribute_assignment.rb +17 -19
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -7
- data/lib/active_record/attribute_methods/dirty.rb +101 -40
- data/lib/active_record/attribute_methods/primary_key.rb +20 -25
- data/lib/active_record/attribute_methods/query.rb +4 -8
- data/lib/active_record/attribute_methods/read.rb +14 -56
- data/lib/active_record/attribute_methods/serialization.rb +12 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
- data/lib/active_record/attribute_methods/write.rb +18 -34
- data/lib/active_record/attribute_methods.rb +81 -143
- data/lib/active_record/attributes.rb +46 -9
- data/lib/active_record/autosave_association.rb +57 -42
- data/lib/active_record/base.rb +4 -17
- data/lib/active_record/callbacks.rb +158 -43
- data/lib/active_record/coders/yaml_column.rb +16 -7
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +272 -130
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -36
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -146
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -14
- data/lib/active_record/connection_adapters/abstract/quoting.rb +107 -47
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -110
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +211 -90
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -4
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +385 -144
- data/lib/active_record/connection_adapters/abstract/transaction.rb +167 -69
- data/lib/active_record/connection_adapters/abstract_adapter.rb +229 -99
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +243 -275
- data/lib/active_record/connection_adapters/column.rb +30 -12
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +88 -32
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/quoting.rb +59 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +18 -7
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +142 -19
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +53 -18
- data/lib/active_record/connection_adapters/pool_config.rb +73 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +37 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +40 -54
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +73 -10
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +19 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +120 -100
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +225 -121
- data/lib/active_record/connection_adapters/schema_cache.rb +159 -21
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +17 -6
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +146 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +77 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +174 -186
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_adapters.rb +52 -0
- data/lib/active_record/connection_handling.rb +293 -33
- data/lib/active_record/core.rb +341 -99
- data/lib/active_record/counter_cache.rb +8 -30
- data/lib/active_record/database_configurations/connection_url_resolver.rb +99 -0
- data/lib/active_record/database_configurations/database_config.rb +80 -0
- data/lib/active_record/database_configurations/hash_config.rb +96 -0
- data/lib/active_record/database_configurations/url_config.rb +53 -0
- data/lib/active_record/database_configurations.rb +273 -0
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +3 -4
- data/lib/active_record/enum.rb +108 -36
- data/lib/active_record/errors.rb +62 -19
- data/lib/active_record/explain.rb +10 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +10 -17
- data/lib/active_record/fixture_set/model_metadata.rb +32 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +200 -481
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +53 -24
- data/lib/active_record/insert_all.rb +212 -0
- data/lib/active_record/integration.rb +67 -17
- data/lib/active_record/internal_metadata.rb +28 -9
- data/lib/active_record/legacy_yaml_adapter.rb +7 -3
- data/lib/active_record/locking/optimistic.rb +37 -23
- data/lib/active_record/locking/pessimistic.rb +9 -5
- data/lib/active_record/log_subscriber.rb +35 -35
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/migration/command_recorder.rb +96 -44
- data/lib/active_record/migration/compatibility.rb +145 -64
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/migration.rb +206 -157
- data/lib/active_record/model_schema.rb +148 -22
- data/lib/active_record/nested_attributes.rb +4 -7
- data/lib/active_record/no_touching.rb +8 -1
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +267 -59
- data/lib/active_record/query_cache.rb +21 -4
- data/lib/active_record/querying.rb +40 -23
- data/lib/active_record/railtie.rb +113 -74
- data/lib/active_record/railties/console_sandbox.rb +2 -4
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +411 -80
- data/lib/active_record/readonly_attributes.rb +4 -0
- data/lib/active_record/reflection.rb +109 -93
- data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
- data/lib/active_record/relation/batches.rb +44 -35
- data/lib/active_record/relation/calculations.rb +157 -90
- data/lib/active_record/relation/delegation.rb +35 -50
- data/lib/active_record/relation/finder_methods.rb +64 -39
- data/lib/active_record/relation/from_clause.rb +5 -1
- data/lib/active_record/relation/merger.rb +32 -40
- data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +11 -10
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/predicate_builder.rb +62 -45
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +478 -187
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +9 -9
- data/lib/active_record/relation/where_clause.rb +115 -62
- data/lib/active_record/relation.rb +379 -115
- data/lib/active_record/result.rb +64 -38
- data/lib/active_record/runtime_registry.rb +2 -2
- data/lib/active_record/sanitization.rb +22 -41
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +54 -9
- data/lib/active_record/schema_migration.rb +7 -9
- data/lib/active_record/scoping/default.rb +4 -8
- data/lib/active_record/scoping/named.rb +17 -24
- data/lib/active_record/scoping.rb +8 -9
- data/lib/active_record/secure_token.rb +16 -8
- data/lib/active_record/serialization.rb +5 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +49 -6
- data/lib/active_record/store.rb +94 -10
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +42 -43
- data/lib/active_record/tasks/database_tasks.rb +277 -81
- data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
- data/lib/active_record/tasks/postgresql_database_tasks.rb +27 -32
- data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +291 -0
- data/lib/active_record/timestamp.rb +43 -32
- data/lib/active_record/touch_later.rb +23 -22
- data/lib/active_record/transactions.rb +62 -118
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type/adapter_specific_registry.rb +3 -13
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +6 -3
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type.rb +10 -5
- data/lib/active_record/type_caster/connection.rb +15 -15
- data/lib/active_record/type_caster/map.rb +8 -8
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/uniqueness.rb +38 -30
- data/lib/active_record/validations.rb +4 -3
- data/lib/active_record.rb +13 -12
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +41 -0
- data/lib/arel/collectors/bind.rb +29 -0
- data/lib/arel/collectors/composite.rb +39 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +27 -0
- data/lib/arel/collectors/substitute_binds.rb +35 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +126 -0
- data/lib/arel/nodes/bind_param.rb +44 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +62 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +15 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +11 -0
- data/lib/arel/nodes/homogeneous_in.rb +76 -0
- data/lib/arel/nodes/in.rb +15 -0
- data/lib/arel/nodes/infix_operation.rb +92 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +51 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +19 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +31 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +44 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/nodes.rb +70 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +250 -0
- data/lib/arel/select_manager.rb +270 -0
- data/lib/arel/table.rb +118 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/dot.rb +308 -0
- data/lib/arel/visitors/mysql.rb +93 -0
- data/lib/arel/visitors/postgresql.rb +120 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +899 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors.rb +13 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +54 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
- data/lib/rails/generators/active_record/migration.rb +19 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +118 -32
- data/lib/active_record/attribute_decorators.rb +0 -90
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
- data/lib/active_record/relation/where_clause_factory.rb +0 -34
data/lib/active_record/core.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/core_ext/enumerable"
|
3
4
|
require "active_support/core_ext/hash/indifferent_access"
|
4
5
|
require "active_support/core_ext/string/filters"
|
6
|
+
require "active_support/parameter_filter"
|
5
7
|
require "concurrent/map"
|
6
8
|
|
7
9
|
module ActiveRecord
|
@@ -24,9 +26,21 @@ module ActiveRecord
|
|
24
26
|
# their relevant queries. Defaults to false.
|
25
27
|
mattr_accessor :verbose_query_logs, instance_writer: false, default: false
|
26
28
|
|
29
|
+
##
|
30
|
+
# :singleton-method:
|
31
|
+
#
|
32
|
+
# Specifies the names of the queues used by background jobs.
|
33
|
+
mattr_accessor :queues, instance_accessor: false, default: {}
|
34
|
+
|
35
|
+
##
|
36
|
+
# :singleton-method:
|
37
|
+
#
|
38
|
+
# Specifies the job used to destroy associations in the background
|
39
|
+
class_attribute :destroy_association_async_job, instance_writer: false, instance_predicate: false, default: false
|
40
|
+
|
27
41
|
##
|
28
42
|
# Contains the database configuration - as is typically stored in config/database.yml -
|
29
|
-
# as
|
43
|
+
# as an ActiveRecord::DatabaseConfigurations object.
|
30
44
|
#
|
31
45
|
# For example, the following database.yml...
|
32
46
|
#
|
@@ -40,22 +54,18 @@ module ActiveRecord
|
|
40
54
|
#
|
41
55
|
# ...would result in ActiveRecord::Base.configurations to look like this:
|
42
56
|
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# 'adapter' => 'sqlite3',
|
50
|
-
# 'database' => 'db/production.sqlite3'
|
51
|
-
# }
|
52
|
-
# }
|
57
|
+
# #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
58
|
+
# #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
59
|
+
# @name="primary", @config={adapter: "sqlite3", database: "db/development.sqlite3"}>,
|
60
|
+
# #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90 @env_name="production",
|
61
|
+
# @name="primary", @config={adapter: "sqlite3", database: "db/production.sqlite3"}>
|
62
|
+
# ]>
|
53
63
|
def self.configurations=(config)
|
54
|
-
@@configurations = ActiveRecord::
|
64
|
+
@@configurations = ActiveRecord::DatabaseConfigurations.new(config)
|
55
65
|
end
|
56
66
|
self.configurations = {}
|
57
67
|
|
58
|
-
# Returns fully resolved
|
68
|
+
# Returns fully resolved ActiveRecord::DatabaseConfigurations object
|
59
69
|
def self.configurations
|
60
70
|
@@configurations
|
61
71
|
end
|
@@ -83,14 +93,6 @@ module ActiveRecord
|
|
83
93
|
# scope being ignored is error-worthy, rather than a warning.
|
84
94
|
mattr_accessor :error_on_ignored_order, instance_writer: false, default: false
|
85
95
|
|
86
|
-
# :singleton-method:
|
87
|
-
# Specify the behavior for unsafe raw query methods. Values are as follows
|
88
|
-
# deprecated - Warnings are logged when unsafe raw SQL is passed to
|
89
|
-
# query methods.
|
90
|
-
# disabled - Unsafe raw SQL passed to query methods results in
|
91
|
-
# UnknownAttributeReference exception.
|
92
|
-
mattr_accessor :allow_unsafe_raw_sql, instance_writer: false, default: :deprecated
|
93
|
-
|
94
96
|
##
|
95
97
|
# :singleton-method:
|
96
98
|
# Specify whether or not to use timestamps for migration versions
|
@@ -99,14 +101,14 @@ module ActiveRecord
|
|
99
101
|
##
|
100
102
|
# :singleton-method:
|
101
103
|
# Specify whether schema dump should happen at the end of the
|
102
|
-
# db:migrate
|
104
|
+
# db:migrate rails command. This is true by default, which is useful for the
|
103
105
|
# development environment. This should ideally be false in the production
|
104
106
|
# environment where dumping schema is rarely needed.
|
105
107
|
mattr_accessor :dump_schema_after_migration, instance_writer: false, default: true
|
106
108
|
|
107
109
|
##
|
108
110
|
# :singleton-method:
|
109
|
-
# Specifies which database schemas to dump when calling db:
|
111
|
+
# Specifies which database schemas to dump when calling db:schema:dump.
|
110
112
|
# If the value is :schema_search_path (the default), any schemas listed in
|
111
113
|
# schema_search_path are dumped. Use :all to dump all schemas regardless
|
112
114
|
# of schema_search_path, or a string of comma separated schemas for a
|
@@ -121,39 +123,200 @@ module ActiveRecord
|
|
121
123
|
# potentially cause memory bloat.
|
122
124
|
mattr_accessor :warn_on_records_fetched_greater_than, instance_writer: false
|
123
125
|
|
126
|
+
##
|
127
|
+
# :singleton-method:
|
128
|
+
# Show a warning when Rails couldn't parse your database.yml
|
129
|
+
# for multiple databases.
|
130
|
+
mattr_accessor :suppress_multiple_database_warning, instance_writer: false, default: false
|
131
|
+
|
124
132
|
mattr_accessor :maintain_test_schema, instance_accessor: false
|
125
133
|
|
126
|
-
|
134
|
+
class_attribute :belongs_to_required_by_default, instance_accessor: false
|
127
135
|
|
128
136
|
##
|
129
137
|
# :singleton-method:
|
138
|
+
# Set the application to log or raise when an association violates strict loading.
|
139
|
+
# Defaults to :raise.
|
140
|
+
mattr_accessor :action_on_strict_loading_violation, instance_accessor: false, default: :raise
|
141
|
+
|
142
|
+
class_attribute :strict_loading_by_default, instance_accessor: false, default: false
|
143
|
+
|
144
|
+
mattr_accessor :writing_role, instance_accessor: false, default: :writing
|
145
|
+
|
146
|
+
mattr_accessor :reading_role, instance_accessor: false, default: :reading
|
147
|
+
|
148
|
+
mattr_accessor :has_many_inversing, instance_accessor: false, default: false
|
149
|
+
|
150
|
+
class_attribute :default_connection_handler, instance_writer: false
|
151
|
+
|
152
|
+
class_attribute :default_role, instance_writer: false
|
153
|
+
|
154
|
+
class_attribute :default_shard, instance_writer: false
|
155
|
+
|
156
|
+
mattr_accessor :legacy_connection_handling, instance_writer: false, default: true
|
157
|
+
|
130
158
|
# Application configurable boolean that instructs the YAML Coder to use
|
131
159
|
# an unsafe load if set to true.
|
132
160
|
mattr_accessor :use_yaml_unsafe_load, instance_writer: false, default: false
|
133
161
|
|
134
162
|
# Application configurable array that provides additional permitted classes
|
135
163
|
# to Psych safe_load in the YAML Coder
|
136
|
-
mattr_accessor :yaml_column_permitted_classes, instance_writer: false, default: []
|
164
|
+
mattr_accessor :yaml_column_permitted_classes, instance_writer: false, default: [Symbol]
|
137
165
|
|
138
|
-
|
166
|
+
##
|
167
|
+
# :singleton-method:
|
168
|
+
# Application configurable boolean that denotes whether or not to raise
|
169
|
+
# an exception when the PostgreSQLAdapter is provided with an integer that is
|
170
|
+
# wider than signed 64bit representation
|
171
|
+
mattr_accessor :raise_int_wider_than_64bit, instance_writer: false, default: true
|
172
|
+
|
173
|
+
self.filter_attributes = []
|
139
174
|
|
140
175
|
def self.connection_handler
|
141
|
-
|
176
|
+
Thread.current.thread_variable_get(:ar_connection_handler) || default_connection_handler
|
142
177
|
end
|
143
178
|
|
144
179
|
def self.connection_handler=(handler)
|
145
|
-
|
180
|
+
Thread.current.thread_variable_set(:ar_connection_handler, handler)
|
146
181
|
end
|
147
182
|
|
148
|
-
self.
|
149
|
-
|
183
|
+
def self.connection_handlers
|
184
|
+
unless legacy_connection_handling
|
185
|
+
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
|
186
|
+
end
|
150
187
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
188
|
+
@@connection_handlers ||= {}
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.connection_handlers=(handlers)
|
192
|
+
unless legacy_connection_handling
|
193
|
+
raise NotImplementedError, "The new connection handling does not setting support multiple connection handlers."
|
194
|
+
end
|
195
|
+
|
196
|
+
@@connection_handlers = handlers
|
197
|
+
end
|
198
|
+
|
199
|
+
# Returns the symbol representing the current connected role.
|
200
|
+
#
|
201
|
+
# ActiveRecord::Base.connected_to(role: :writing) do
|
202
|
+
# ActiveRecord::Base.current_role #=> :writing
|
203
|
+
# end
|
204
|
+
#
|
205
|
+
# ActiveRecord::Base.connected_to(role: :reading) do
|
206
|
+
# ActiveRecord::Base.current_role #=> :reading
|
207
|
+
# end
|
208
|
+
def self.current_role
|
209
|
+
if ActiveRecord::Base.legacy_connection_handling
|
210
|
+
connection_handlers.key(connection_handler) || default_role
|
211
|
+
else
|
212
|
+
connected_to_stack.reverse_each do |hash|
|
213
|
+
return hash[:role] if hash[:role] && hash[:klasses].include?(Base)
|
214
|
+
return hash[:role] if hash[:role] && hash[:klasses].include?(connection_classes)
|
215
|
+
end
|
216
|
+
|
217
|
+
default_role
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# Returns the symbol representing the current connected shard.
|
222
|
+
#
|
223
|
+
# ActiveRecord::Base.connected_to(role: :reading) do
|
224
|
+
# ActiveRecord::Base.current_shard #=> :default
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# ActiveRecord::Base.connected_to(role: :writing, shard: :one) do
|
228
|
+
# ActiveRecord::Base.current_shard #=> :one
|
229
|
+
# end
|
230
|
+
def self.current_shard
|
231
|
+
connected_to_stack.reverse_each do |hash|
|
232
|
+
return hash[:shard] if hash[:shard] && hash[:klasses].include?(Base)
|
233
|
+
return hash[:shard] if hash[:shard] && hash[:klasses].include?(connection_classes)
|
234
|
+
end
|
235
|
+
|
236
|
+
default_shard
|
237
|
+
end
|
238
|
+
|
239
|
+
# Returns the symbol representing the current setting for
|
240
|
+
# preventing writes.
|
241
|
+
#
|
242
|
+
# ActiveRecord::Base.connected_to(role: :reading) do
|
243
|
+
# ActiveRecord::Base.current_preventing_writes #=> true
|
244
|
+
# end
|
245
|
+
#
|
246
|
+
# ActiveRecord::Base.connected_to(role: :writing) do
|
247
|
+
# ActiveRecord::Base.current_preventing_writes #=> false
|
248
|
+
# end
|
249
|
+
def self.current_preventing_writes
|
250
|
+
if legacy_connection_handling
|
251
|
+
connection_handler.prevent_writes
|
252
|
+
else
|
253
|
+
connected_to_stack.reverse_each do |hash|
|
254
|
+
return hash[:prevent_writes] if !hash[:prevent_writes].nil? && hash[:klasses].include?(Base)
|
255
|
+
return hash[:prevent_writes] if !hash[:prevent_writes].nil? && hash[:klasses].include?(connection_classes)
|
256
|
+
end
|
257
|
+
|
258
|
+
false
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def self.connected_to_stack # :nodoc:
|
263
|
+
if connected_to_stack = Thread.current.thread_variable_get(:ar_connected_to_stack)
|
264
|
+
connected_to_stack
|
265
|
+
else
|
266
|
+
connected_to_stack = Concurrent::Array.new
|
267
|
+
Thread.current.thread_variable_set(:ar_connected_to_stack, connected_to_stack)
|
268
|
+
connected_to_stack
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def self.connection_class=(b) # :nodoc:
|
273
|
+
@connection_class = b
|
274
|
+
end
|
275
|
+
|
276
|
+
def self.connection_class # :nodoc
|
277
|
+
@connection_class ||= false
|
155
278
|
end
|
156
279
|
|
280
|
+
def self.connection_class? # :nodoc:
|
281
|
+
self.connection_class
|
282
|
+
end
|
283
|
+
|
284
|
+
def self.connection_classes # :nodoc:
|
285
|
+
klass = self
|
286
|
+
|
287
|
+
until klass == Base
|
288
|
+
break if klass.connection_class?
|
289
|
+
klass = klass.superclass
|
290
|
+
end
|
291
|
+
|
292
|
+
klass
|
293
|
+
end
|
294
|
+
|
295
|
+
def self.allow_unsafe_raw_sql # :nodoc:
|
296
|
+
ActiveSupport::Deprecation.warn("ActiveRecord::Base.allow_unsafe_raw_sql is deprecated and will be removed in Rails 7.0")
|
297
|
+
end
|
298
|
+
|
299
|
+
def self.allow_unsafe_raw_sql=(value) # :nodoc:
|
300
|
+
ActiveSupport::Deprecation.warn("ActiveRecord::Base.allow_unsafe_raw_sql= is deprecated and will be removed in Rails 7.0")
|
301
|
+
end
|
302
|
+
|
303
|
+
self.default_connection_handler = ConnectionAdapters::ConnectionHandler.new
|
304
|
+
self.default_role = writing_role
|
305
|
+
self.default_shard = :default
|
306
|
+
|
307
|
+
def self.strict_loading_violation!(owner:, reflection:) # :nodoc:
|
308
|
+
case action_on_strict_loading_violation
|
309
|
+
when :raise
|
310
|
+
message = "`#{owner}` is marked for strict_loading. The `#{reflection.klass}` association named `:#{reflection.name}` cannot be lazily loaded."
|
311
|
+
raise ActiveRecord::StrictLoadingViolationError.new(message)
|
312
|
+
when :log
|
313
|
+
name = "strict_loading_violation.active_record"
|
314
|
+
ActiveSupport::Notifications.instrument(name, owner: owner, reflection: reflection)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
module ClassMethods
|
157
320
|
def initialize_find_by_cache # :nodoc:
|
158
321
|
@find_by_statement_cache = { true => Concurrent::Map.new, false => Concurrent::Map.new }
|
159
322
|
end
|
@@ -161,16 +324,20 @@ module ActiveRecord
|
|
161
324
|
def inherited(child_class) # :nodoc:
|
162
325
|
# initialize cache at class definition for thread safety
|
163
326
|
child_class.initialize_find_by_cache
|
327
|
+
unless child_class.base_class?
|
328
|
+
klass = self
|
329
|
+
until klass.base_class?
|
330
|
+
klass.initialize_find_by_cache
|
331
|
+
klass = klass.superclass
|
332
|
+
end
|
333
|
+
end
|
164
334
|
super
|
165
335
|
end
|
166
336
|
|
167
337
|
def find(*ids) # :nodoc:
|
168
338
|
# We don't have cache keys for this stuff yet
|
169
339
|
return super unless ids.length == 1
|
170
|
-
return super if block_given? ||
|
171
|
-
primary_key.nil? ||
|
172
|
-
scope_attributes? ||
|
173
|
-
columns_hash.include?(inheritance_column)
|
340
|
+
return super if block_given? || primary_key.nil? || scope_attributes?
|
174
341
|
|
175
342
|
id = ids.first
|
176
343
|
|
@@ -182,44 +349,49 @@ module ActiveRecord
|
|
182
349
|
where(key => params.bind).limit(1)
|
183
350
|
}
|
184
351
|
|
185
|
-
|
186
|
-
|
187
|
-
raise RecordNotFound.new("Couldn't find #{name} with '#{primary_key}'=#{id}",
|
188
|
-
name, primary_key, id)
|
189
|
-
end
|
190
|
-
record
|
191
|
-
rescue ::RangeError
|
192
|
-
raise RecordNotFound.new("Couldn't find #{name} with an out of range value for '#{primary_key}'",
|
193
|
-
name, primary_key)
|
352
|
+
statement.execute([id], connection).first ||
|
353
|
+
raise(RecordNotFound.new("Couldn't find #{name} with '#{key}'=#{id}", name, key, id))
|
194
354
|
end
|
195
355
|
|
196
356
|
def find_by(*args) # :nodoc:
|
197
|
-
return super if scope_attributes?
|
198
|
-
columns_hash.key?(inheritance_column) && base_class != self
|
357
|
+
return super if scope_attributes?
|
199
358
|
|
200
359
|
hash = args.first
|
360
|
+
return super unless Hash === hash
|
201
361
|
|
202
|
-
|
203
|
-
|
204
|
-
|
362
|
+
hash = hash.each_with_object({}) do |(key, value), h|
|
363
|
+
key = key.to_s
|
364
|
+
key = attribute_aliases[key] || key
|
205
365
|
|
206
|
-
|
207
|
-
return super unless hash.keys.all? { |k| columns_hash.has_key?(k.to_s) }
|
366
|
+
return super if reflect_on_aggregation(key)
|
208
367
|
|
209
|
-
|
368
|
+
reflection = _reflect_on_association(key)
|
369
|
+
|
370
|
+
if !reflection
|
371
|
+
value = value.id if value.respond_to?(:id)
|
372
|
+
elsif reflection.belongs_to? && !reflection.polymorphic?
|
373
|
+
key = reflection.join_foreign_key
|
374
|
+
pkey = reflection.join_primary_key
|
375
|
+
value = value.public_send(pkey) if value.respond_to?(pkey)
|
376
|
+
end
|
377
|
+
|
378
|
+
if !columns_hash.key?(key) || StatementCache.unsupported_value?(value)
|
379
|
+
return super
|
380
|
+
end
|
381
|
+
|
382
|
+
h[key] = value
|
383
|
+
end
|
210
384
|
|
385
|
+
keys = hash.keys
|
211
386
|
statement = cached_find_by_statement(keys) { |params|
|
212
|
-
wheres = keys.
|
213
|
-
o[param] = params.bind
|
214
|
-
}
|
387
|
+
wheres = keys.index_with { params.bind }
|
215
388
|
where(wheres).limit(1)
|
216
389
|
}
|
390
|
+
|
217
391
|
begin
|
218
392
|
statement.execute(hash.values, connection).first
|
219
393
|
rescue TypeError
|
220
394
|
raise ActiveRecord::StatementInvalid
|
221
|
-
rescue ::RangeError
|
222
|
-
nil
|
223
395
|
end
|
224
396
|
end
|
225
397
|
|
@@ -231,7 +403,7 @@ module ActiveRecord
|
|
231
403
|
generated_association_methods
|
232
404
|
end
|
233
405
|
|
234
|
-
def generated_association_methods
|
406
|
+
def generated_association_methods # :nodoc:
|
235
407
|
@generated_association_methods ||= begin
|
236
408
|
mod = const_set(:GeneratedAssociationMethods, Module.new)
|
237
409
|
private_constant :GeneratedAssociationMethods
|
@@ -241,8 +413,34 @@ module ActiveRecord
|
|
241
413
|
end
|
242
414
|
end
|
243
415
|
|
416
|
+
# Returns columns which shouldn't be exposed while calling +#inspect+.
|
417
|
+
def filter_attributes
|
418
|
+
if defined?(@filter_attributes)
|
419
|
+
@filter_attributes
|
420
|
+
else
|
421
|
+
superclass.filter_attributes
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
# Specifies columns which shouldn't be exposed while calling +#inspect+.
|
426
|
+
def filter_attributes=(filter_attributes)
|
427
|
+
@inspection_filter = nil
|
428
|
+
@filter_attributes = filter_attributes
|
429
|
+
end
|
430
|
+
|
431
|
+
def inspection_filter # :nodoc:
|
432
|
+
if defined?(@filter_attributes)
|
433
|
+
@inspection_filter ||= begin
|
434
|
+
mask = InspectionMask.new(ActiveSupport::ParameterFilter::FILTERED)
|
435
|
+
ActiveSupport::ParameterFilter.new(@filter_attributes, mask: mask)
|
436
|
+
end
|
437
|
+
else
|
438
|
+
superclass.inspection_filter
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
244
442
|
# Returns a string like 'Post(id:integer, title:string, body:text)'
|
245
|
-
def inspect
|
443
|
+
def inspect # :nodoc:
|
246
444
|
if self == Base
|
247
445
|
super
|
248
446
|
elsif abstract_class?
|
@@ -258,7 +456,7 @@ module ActiveRecord
|
|
258
456
|
end
|
259
457
|
|
260
458
|
# Overwrite the default class equality method to provide support for decorated models.
|
261
|
-
def ===(object)
|
459
|
+
def ===(object) # :nodoc:
|
262
460
|
object.is_a?(self)
|
263
461
|
end
|
264
462
|
|
@@ -268,13 +466,13 @@ module ActiveRecord
|
|
268
466
|
# scope :published_and_commented, -> { published.and(arel_table[:comments_count].gt(0)) }
|
269
467
|
# end
|
270
468
|
def arel_table # :nodoc:
|
271
|
-
@arel_table ||= Arel::Table.new(table_name,
|
469
|
+
@arel_table ||= Arel::Table.new(table_name, klass: self)
|
272
470
|
end
|
273
471
|
|
274
472
|
def arel_attribute(name, table = arel_table) # :nodoc:
|
275
|
-
name = attribute_alias(name) if attribute_alias?(name)
|
276
473
|
table[name]
|
277
474
|
end
|
475
|
+
deprecate :arel_attribute
|
278
476
|
|
279
477
|
def predicate_builder # :nodoc:
|
280
478
|
@predicate_builder ||= PredicateBuilder.new(table_metadata)
|
@@ -284,19 +482,21 @@ module ActiveRecord
|
|
284
482
|
TypeCaster::Map.new(self)
|
285
483
|
end
|
286
484
|
|
287
|
-
|
485
|
+
def _internal? # :nodoc:
|
486
|
+
false
|
487
|
+
end
|
288
488
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
489
|
+
def cached_find_by_statement(key, &block) # :nodoc:
|
490
|
+
cache = @find_by_statement_cache[connection.prepared_statements]
|
491
|
+
cache.compute_if_absent(key) { StatementCache.create(connection, &block) }
|
492
|
+
end
|
293
493
|
|
494
|
+
private
|
294
495
|
def relation
|
295
496
|
relation = Relation.create(self)
|
296
497
|
|
297
498
|
if finder_needs_type_condition? && !ignore_default_scope?
|
298
499
|
relation.where!(type_condition)
|
299
|
-
relation.create_with!(inheritance_column.to_s => sti_name)
|
300
500
|
else
|
301
501
|
relation
|
302
502
|
end
|
@@ -316,7 +516,7 @@ module ActiveRecord
|
|
316
516
|
# # Instantiates a single new object
|
317
517
|
# User.new(first_name: 'Jamie')
|
318
518
|
def initialize(attributes = nil)
|
319
|
-
|
519
|
+
@new_record = true
|
320
520
|
@attributes = self.class._default_attributes.deep_dup
|
321
521
|
|
322
522
|
init_internals
|
@@ -342,15 +542,21 @@ module ActiveRecord
|
|
342
542
|
# post = Post.allocate
|
343
543
|
# post.init_with(coder)
|
344
544
|
# post.title # => 'hello world'
|
345
|
-
def init_with(coder)
|
545
|
+
def init_with(coder, &block)
|
346
546
|
coder = LegacyYamlAdapter.convert(self.class, coder)
|
347
|
-
|
348
|
-
|
349
|
-
|
547
|
+
attributes = self.class.yaml_encoder.decode(coder)
|
548
|
+
init_with_attributes(attributes, coder["new_record"], &block)
|
549
|
+
end
|
350
550
|
|
351
|
-
|
551
|
+
##
|
552
|
+
# Initialize an empty model object from +attributes+.
|
553
|
+
# +attributes+ should be an attributes object, and unlike the
|
554
|
+
# `initialize` method, no assignment calls are made per attribute.
|
555
|
+
def init_with_attributes(attributes, new_record = false) # :nodoc:
|
556
|
+
@new_record = new_record
|
557
|
+
@attributes = attributes
|
352
558
|
|
353
|
-
|
559
|
+
init_internals
|
354
560
|
|
355
561
|
yield self if block_given?
|
356
562
|
|
@@ -389,14 +595,14 @@ module ActiveRecord
|
|
389
595
|
##
|
390
596
|
def initialize_dup(other) # :nodoc:
|
391
597
|
@attributes = @attributes.deep_dup
|
392
|
-
@attributes.reset(
|
598
|
+
@attributes.reset(@primary_key)
|
393
599
|
|
394
600
|
_run_initialize_callbacks
|
395
601
|
|
396
602
|
@new_record = true
|
603
|
+
@previously_new_record = false
|
397
604
|
@destroyed = false
|
398
|
-
@_start_transaction_state =
|
399
|
-
@transaction_state = nil
|
605
|
+
@_start_transaction_state = nil
|
400
606
|
|
401
607
|
super
|
402
608
|
end
|
@@ -468,12 +674,35 @@ module ActiveRecord
|
|
468
674
|
end
|
469
675
|
end
|
470
676
|
|
471
|
-
|
472
|
-
|
677
|
+
def present? # :nodoc:
|
678
|
+
true
|
679
|
+
end
|
680
|
+
|
681
|
+
def blank? # :nodoc:
|
682
|
+
false
|
683
|
+
end
|
684
|
+
|
685
|
+
# Returns +true+ if the record is read only.
|
473
686
|
def readonly?
|
474
687
|
@readonly
|
475
688
|
end
|
476
689
|
|
690
|
+
# Returns +true+ if the record is in strict_loading mode.
|
691
|
+
def strict_loading?
|
692
|
+
@strict_loading
|
693
|
+
end
|
694
|
+
|
695
|
+
# Sets the record to strict_loading mode. This will raise an error
|
696
|
+
# if the record tries to lazily load an association.
|
697
|
+
#
|
698
|
+
# user = User.first
|
699
|
+
# user.strict_loading!
|
700
|
+
# user.comments.to_a
|
701
|
+
# => ActiveRecord::StrictLoadingViolationError
|
702
|
+
def strict_loading!
|
703
|
+
@strict_loading = true
|
704
|
+
end
|
705
|
+
|
477
706
|
# Marks this record as read only.
|
478
707
|
def readonly!
|
479
708
|
@readonly = true
|
@@ -489,7 +718,7 @@ module ActiveRecord
|
|
489
718
|
# allocated but not initialized.
|
490
719
|
inspection = if defined?(@attributes) && @attributes
|
491
720
|
self.class.attribute_names.collect do |name|
|
492
|
-
if
|
721
|
+
if _has_attribute?(name)
|
493
722
|
"#{name}: #{attribute_for_inspect(name)}"
|
494
723
|
end
|
495
724
|
end.compact.join(", ")
|
@@ -506,15 +735,16 @@ module ActiveRecord
|
|
506
735
|
return super if custom_inspect_method_defined?
|
507
736
|
pp.object_address_group(self) do
|
508
737
|
if defined?(@attributes) && @attributes
|
509
|
-
|
510
|
-
pp.seplist(
|
511
|
-
column_value = read_attribute(column_name)
|
738
|
+
attr_names = self.class.attribute_names.select { |name| _has_attribute?(name) }
|
739
|
+
pp.seplist(attr_names, proc { pp.text "," }) do |attr_name|
|
512
740
|
pp.breakable " "
|
513
741
|
pp.group(1) do
|
514
|
-
pp.text
|
742
|
+
pp.text attr_name
|
515
743
|
pp.text ":"
|
516
744
|
pp.breakable
|
517
|
-
|
745
|
+
value = _read_attribute(attr_name)
|
746
|
+
value = inspection_filter.filter_param(attr_name, value) unless value.nil?
|
747
|
+
pp.pp value
|
518
748
|
end
|
519
749
|
end
|
520
750
|
else
|
@@ -526,11 +756,15 @@ module ActiveRecord
|
|
526
756
|
|
527
757
|
# Returns a hash of the given methods with their names as keys and returned values as values.
|
528
758
|
def slice(*methods)
|
529
|
-
|
759
|
+
methods.flatten.index_with { |method| public_send(method) }.with_indifferent_access
|
530
760
|
end
|
531
761
|
|
532
|
-
|
762
|
+
# Returns an array of the values returned by the given methods.
|
763
|
+
def values_at(*methods)
|
764
|
+
methods.flatten.map! { |method| public_send(method) }
|
765
|
+
end
|
533
766
|
|
767
|
+
private
|
534
768
|
# +Array#flatten+ will call +#to_ary+ (recursively) on each of the elements of
|
535
769
|
# the array, and then rescues from the possible +NoMethodError+. If those elements are
|
536
770
|
# +ActiveRecord::Base+'s, then this triggers the various +method_missing+'s that we have,
|
@@ -544,26 +778,34 @@ module ActiveRecord
|
|
544
778
|
end
|
545
779
|
|
546
780
|
def init_internals
|
781
|
+
@primary_key = self.class.primary_key
|
547
782
|
@readonly = false
|
783
|
+
@previously_new_record = false
|
548
784
|
@destroyed = false
|
549
785
|
@marked_for_destruction = false
|
550
786
|
@destroyed_by_association = nil
|
551
|
-
@
|
552
|
-
@
|
553
|
-
|
787
|
+
@_start_transaction_state = nil
|
788
|
+
@strict_loading = self.class.strict_loading_by_default
|
789
|
+
|
790
|
+
self.class.define_attribute_methods
|
554
791
|
end
|
555
792
|
|
556
793
|
def initialize_internals_callback
|
557
794
|
end
|
558
795
|
|
559
|
-
def
|
560
|
-
|
561
|
-
|
796
|
+
def custom_inspect_method_defined?
|
797
|
+
self.class.instance_method(:inspect).owner != ActiveRecord::Base.instance_method(:inspect).owner
|
798
|
+
end
|
799
|
+
|
800
|
+
class InspectionMask < DelegateClass(::String)
|
801
|
+
def pretty_print(pp)
|
802
|
+
pp.text __getobj__
|
562
803
|
end
|
563
804
|
end
|
805
|
+
private_constant :InspectionMask
|
564
806
|
|
565
|
-
def
|
566
|
-
self.class.
|
807
|
+
def inspection_filter
|
808
|
+
self.class.inspection_filter
|
567
809
|
end
|
568
810
|
end
|
569
811
|
end
|