activerecord 6.1.7.4 → 7.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1449 -1014
- data/README.rdoc +3 -3
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/association_relation.rb +0 -10
- data/lib/active_record/associations/association.rb +33 -17
- data/lib/active_record/associations/association_scope.rb +1 -3
- data/lib/active_record/associations/belongs_to_association.rb +15 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +8 -2
- data/lib/active_record/associations/builder/belongs_to.rb +19 -6
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- 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 +2 -2
- data/lib/active_record/associations/collection_association.rb +19 -21
- data/lib/active_record/associations/collection_proxy.rb +10 -5
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/has_many_association.rb +8 -5
- data/lib/active_record/associations/has_many_through_association.rb +2 -1
- data/lib/active_record/associations/has_one_association.rb +14 -7
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +23 -15
- data/lib/active_record/associations/preloader/association.rb +186 -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 +39 -113
- data/lib/active_record/associations/singular_association.rb +15 -7
- data/lib/active_record/associations/through_association.rb +3 -3
- data/lib/active_record/associations.rb +138 -100
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
- data/lib/active_record/attribute_methods/dirty.rb +49 -16
- data/lib/active_record/attribute_methods/primary_key.rb +2 -2
- data/lib/active_record/attribute_methods/query.rb +2 -2
- data/lib/active_record/attribute_methods/read.rb +8 -6
- data/lib/active_record/attribute_methods/serialization.rb +57 -19
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
- data/lib/active_record/attribute_methods/write.rb +7 -10
- data/lib/active_record/attribute_methods.rb +19 -22
- data/lib/active_record/attributes.rb +24 -35
- data/lib/active_record/autosave_association.rb +17 -28
- data/lib/active_record/base.rb +19 -1
- data/lib/active_record/callbacks.rb +14 -16
- data/lib/active_record/coders/yaml_column.rb +4 -8
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +292 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +47 -561
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +0 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +46 -22
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -12
- data/lib/active_record/connection_adapters/abstract/quoting.rb +42 -72
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -17
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +52 -23
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +82 -25
- data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -22
- data/lib/active_record/connection_adapters/abstract_adapter.rb +153 -74
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +112 -84
- data/lib/active_record/connection_adapters/column.rb +4 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +36 -24
- data/lib/active_record/connection_adapters/mysql/quoting.rb +45 -21
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +4 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +7 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +20 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -6
- data/lib/active_record/connection_adapters/pool_config.rb +7 -7
- data/lib/active_record/connection_adapters/postgresql/column.rb +19 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +20 -17
- 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 +1 -1
- 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 +71 -71
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +34 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +21 -1
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +22 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +40 -21
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +207 -106
- data/lib/active_record/connection_adapters/schema_cache.rb +39 -38
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +25 -19
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +28 -16
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +17 -15
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +97 -32
- data/lib/active_record/connection_adapters.rb +6 -5
- data/lib/active_record/connection_handling.rb +49 -55
- data/lib/active_record/core.rb +123 -148
- data/lib/active_record/database_configurations/connection_url_resolver.rb +2 -1
- data/lib/active_record/database_configurations/database_config.rb +12 -9
- data/lib/active_record/database_configurations/hash_config.rb +63 -5
- data/lib/active_record/database_configurations/url_config.rb +2 -2
- data/lib/active_record/database_configurations.rb +15 -32
- data/lib/active_record/delegated_type.rb +53 -12
- data/lib/active_record/destroy_association_async_job.rb +1 -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/cipher/aes256_gcm.rb +98 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +44 -0
- data/lib/active_record/encryption/configurable.rb +67 -0
- data/lib/active_record/encryption/context.rb +35 -0
- data/lib/active_record/encryption/contexts.rb +72 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +206 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -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 +160 -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 +42 -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 +90 -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 +99 -0
- data/lib/active_record/encryption.rb +55 -0
- data/lib/active_record/enum.rb +50 -43
- data/lib/active_record/errors.rb +67 -4
- 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/table_row.rb +41 -6
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +20 -23
- data/lib/active_record/future_result.rb +139 -0
- data/lib/active_record/gem_version.rb +5 -5
- data/lib/active_record/inheritance.rb +55 -17
- data/lib/active_record/insert_all.rb +80 -14
- data/lib/active_record/integration.rb +4 -3
- data/lib/active_record/internal_metadata.rb +1 -5
- 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 +10 -4
- data/lib/active_record/log_subscriber.rb +23 -7
- data/lib/active_record/middleware/database_selector/resolver.rb +6 -10
- data/lib/active_record/middleware/database_selector.rb +18 -6
- data/lib/active_record/middleware/shard_selector.rb +60 -0
- data/lib/active_record/migration/command_recorder.rb +8 -9
- data/lib/active_record/migration/compatibility.rb +91 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +115 -84
- data/lib/active_record/model_schema.rb +58 -59
- data/lib/active_record/nested_attributes.rb +13 -12
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/null_relation.rb +2 -6
- data/lib/active_record/persistence.rb +228 -60
- data/lib/active_record/query_cache.rb +2 -2
- data/lib/active_record/query_logs.rb +149 -0
- data/lib/active_record/querying.rb +16 -6
- data/lib/active_record/railtie.rb +136 -22
- data/lib/active_record/railties/controller_runtime.rb +1 -1
- data/lib/active_record/railties/databases.rake +78 -136
- data/lib/active_record/readonly_attributes.rb +11 -0
- data/lib/active_record/reflection.rb +80 -49
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +6 -6
- data/lib/active_record/relation/calculations.rb +92 -60
- data/lib/active_record/relation/delegation.rb +7 -7
- data/lib/active_record/relation/finder_methods.rb +31 -35
- data/lib/active_record/relation/merger.rb +20 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +20 -1
- data/lib/active_record/relation/predicate_builder.rb +2 -6
- data/lib/active_record/relation/query_attribute.rb +5 -11
- data/lib/active_record/relation/query_methods.rb +285 -68
- data/lib/active_record/relation/record_fetch_warning.rb +7 -9
- data/lib/active_record/relation/spawn_methods.rb +2 -2
- data/lib/active_record/relation/where_clause.rb +10 -19
- data/lib/active_record/relation.rb +189 -88
- data/lib/active_record/result.rb +23 -11
- data/lib/active_record/runtime_registry.rb +9 -13
- data/lib/active_record/sanitization.rb +17 -12
- data/lib/active_record/schema.rb +38 -23
- data/lib/active_record/schema_dumper.rb +29 -19
- data/lib/active_record/schema_migration.rb +4 -4
- data/lib/active_record/scoping/default.rb +60 -13
- data/lib/active_record/scoping/named.rb +3 -11
- data/lib/active_record/scoping.rb +64 -34
- data/lib/active_record/serialization.rb +6 -1
- data/lib/active_record/signed_id.rb +3 -3
- data/lib/active_record/store.rb +2 -2
- data/lib/active_record/suppressor.rb +11 -15
- data/lib/active_record/table_metadata.rb +5 -1
- data/lib/active_record/tasks/database_tasks.rb +127 -60
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -13
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +9 -6
- data/lib/active_record/timestamp.rb +3 -4
- data/lib/active_record/transactions.rb +9 -14
- data/lib/active_record/translation.rb +3 -3
- data/lib/active_record/type/adapter_specific_registry.rb +32 -7
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +2 -2
- data/lib/active_record/type/serialized.rb +5 -5
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/validations/associated.rb +4 -4
- data/lib/active_record/validations/presence.rb +2 -2
- data/lib/active_record/validations/uniqueness.rb +4 -4
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +225 -27
- 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/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/delete_statement.rb +12 -13
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/predications.rb +11 -3
- data/lib/arel/select_manager.rb +10 -4
- data/lib/arel/table.rb +0 -1
- 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 +8 -2
- data/lib/arel/visitors/postgresql.rb +0 -10
- data/lib/arel/visitors/to_sql.rb +58 -2
- data/lib/arel.rb +2 -1
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- 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 +58 -14
@@ -126,9 +126,29 @@ module ActiveRecord
|
|
126
126
|
# +:immutable_string+. This setting does not affect the behavior of
|
127
127
|
# <tt>attribute :foo, :string</tt>. Defaults to false.
|
128
128
|
|
129
|
-
|
130
|
-
|
129
|
+
##
|
130
|
+
# :singleton-method: inheritance_column
|
131
|
+
# :call-seq: inheritance_column
|
132
|
+
#
|
133
|
+
# The name of the table column which stores the class name on single-table
|
134
|
+
# inheritance situations.
|
135
|
+
#
|
136
|
+
# The default inheritance column name is +type+, which means it's a
|
137
|
+
# reserved word inside Active Record. To be able to use single-table
|
138
|
+
# inheritance with another column name, or to use the column +type+ in
|
139
|
+
# your own model for something else, you can set +inheritance_column+:
|
140
|
+
#
|
141
|
+
# self.inheritance_column = 'zoink'
|
142
|
+
|
143
|
+
##
|
144
|
+
# :singleton-method: inheritance_column=
|
145
|
+
# :call-seq: inheritance_column=(column)
|
146
|
+
#
|
147
|
+
# Defines the name of the table column which will store the class name on single-table
|
148
|
+
# inheritance situations.
|
131
149
|
|
150
|
+
included do
|
151
|
+
class_attribute :primary_key_prefix_type, instance_writer: false
|
132
152
|
class_attribute :table_name_prefix, instance_writer: false, default: ""
|
133
153
|
class_attribute :table_name_suffix, instance_writer: false, default: ""
|
134
154
|
class_attribute :schema_migrations_table_name, instance_accessor: false, default: "schema_migrations"
|
@@ -137,8 +157,15 @@ module ActiveRecord
|
|
137
157
|
class_attribute :implicit_order_column, instance_accessor: false
|
138
158
|
class_attribute :immutable_strings_by_default, instance_accessor: false
|
139
159
|
|
160
|
+
class_attribute :inheritance_column, instance_accessor: false, default: "type"
|
161
|
+
singleton_class.class_eval do
|
162
|
+
alias_method :_inheritance_column=, :inheritance_column=
|
163
|
+
private :_inheritance_column=
|
164
|
+
alias_method :inheritance_column=, :real_inheritance_column=
|
165
|
+
end
|
166
|
+
|
140
167
|
self.protected_environments = ["production"]
|
141
|
-
|
168
|
+
|
142
169
|
self.ignored_columns = [].freeze
|
143
170
|
|
144
171
|
delegate :type_for_attribute, :column_for_attribute, to: :class
|
@@ -197,6 +224,21 @@ module ActiveRecord
|
|
197
224
|
# the table name guess for an Invoice class becomes "myapp_invoices".
|
198
225
|
# Invoice::Lineitem becomes "myapp_invoice_lineitems".
|
199
226
|
#
|
227
|
+
# Active Model Naming's +model_name+ is the base name used to guess the
|
228
|
+
# table name. In case a custom Active Model Name is defined, it will be
|
229
|
+
# used for the table name as well:
|
230
|
+
#
|
231
|
+
# class PostRecord < ActiveRecord::Base
|
232
|
+
# class << self
|
233
|
+
# def model_name
|
234
|
+
# ActiveModel::Name.new(self, nil, "Post")
|
235
|
+
# end
|
236
|
+
# end
|
237
|
+
# end
|
238
|
+
#
|
239
|
+
# PostRecord.table_name
|
240
|
+
# # => "posts"
|
241
|
+
#
|
200
242
|
# You can also set your own table name explicitly:
|
201
243
|
#
|
202
244
|
# class Mouse < ActiveRecord::Base
|
@@ -233,7 +275,7 @@ module ActiveRecord
|
|
233
275
|
end
|
234
276
|
|
235
277
|
# Computes the table name, (re)sets it internally, and returns it.
|
236
|
-
def reset_table_name
|
278
|
+
def reset_table_name # :nodoc:
|
237
279
|
self.table_name = if abstract_class?
|
238
280
|
superclass == Base ? nil : superclass.table_name
|
239
281
|
elsif superclass.abstract_class?
|
@@ -243,11 +285,11 @@ module ActiveRecord
|
|
243
285
|
end
|
244
286
|
end
|
245
287
|
|
246
|
-
def full_table_name_prefix
|
288
|
+
def full_table_name_prefix # :nodoc:
|
247
289
|
(module_parents.detect { |p| p.respond_to?(:table_name_prefix) } || self).table_name_prefix
|
248
290
|
end
|
249
291
|
|
250
|
-
def full_table_name_suffix
|
292
|
+
def full_table_name_suffix # :nodoc:
|
251
293
|
(module_parents.detect { |p| p.respond_to?(:table_name_suffix) } || self).table_name_suffix
|
252
294
|
end
|
253
295
|
|
@@ -266,23 +308,8 @@ module ActiveRecord
|
|
266
308
|
@protected_environments = environments.map(&:to_s)
|
267
309
|
end
|
268
310
|
|
269
|
-
|
270
|
-
|
271
|
-
#
|
272
|
-
# The default inheritance column name is +type+, which means it's a
|
273
|
-
# reserved word inside Active Record. To be able to use single-table
|
274
|
-
# inheritance with another column name, or to use the column +type+ in
|
275
|
-
# your own model for something else, you can set +inheritance_column+:
|
276
|
-
#
|
277
|
-
# self.inheritance_column = 'zoink'
|
278
|
-
def inheritance_column
|
279
|
-
(@inheritance_column ||= nil) || superclass.inheritance_column
|
280
|
-
end
|
281
|
-
|
282
|
-
# Sets the value of inheritance_column
|
283
|
-
def inheritance_column=(value)
|
284
|
-
@inheritance_column = value.to_s
|
285
|
-
@explicit_inheritance_column = true
|
311
|
+
def real_inheritance_column=(value) # :nodoc:
|
312
|
+
self._inheritance_column = value.to_s
|
286
313
|
end
|
287
314
|
|
288
315
|
# The list of columns names the model should ignore. Ignored columns won't have attribute
|
@@ -339,7 +366,7 @@ module ActiveRecord
|
|
339
366
|
end
|
340
367
|
end
|
341
368
|
|
342
|
-
def reset_sequence_name
|
369
|
+
def reset_sequence_name # :nodoc:
|
343
370
|
@explicit_sequence_name = false
|
344
371
|
@sequence_name = connection.default_sequence_name(table_name, primary_key)
|
345
372
|
end
|
@@ -486,9 +513,9 @@ module ActiveRecord
|
|
486
513
|
#
|
487
514
|
# The most common usage pattern for this method is probably in a migration,
|
488
515
|
# when just after creating a table you want to populate it with some default
|
489
|
-
# values,
|
516
|
+
# values, e.g.:
|
490
517
|
#
|
491
|
-
# class CreateJobLevels < ActiveRecord::Migration[
|
518
|
+
# class CreateJobLevels < ActiveRecord::Migration[7.0]
|
492
519
|
# def up
|
493
520
|
# create_table :job_levels do |t|
|
494
521
|
# t.integer :id
|
@@ -556,7 +583,6 @@ module ActiveRecord
|
|
556
583
|
@columns_hash.each do |name, column|
|
557
584
|
type = connection.lookup_cast_type_from_column(column)
|
558
585
|
type = _convert_type_from_options(type)
|
559
|
-
warn_if_deprecated_type(column)
|
560
586
|
define_attribute(
|
561
587
|
name,
|
562
588
|
type,
|
@@ -574,21 +600,20 @@ module ActiveRecord
|
|
574
600
|
@content_columns = nil
|
575
601
|
@default_attributes = nil
|
576
602
|
@column_defaults = nil
|
577
|
-
@inheritance_column = nil unless defined?(@explicit_inheritance_column) && @explicit_inheritance_column
|
578
603
|
@attributes_builder = nil
|
579
604
|
@columns = nil
|
580
605
|
@columns_hash = nil
|
581
606
|
@schema_loaded = false
|
582
607
|
@attribute_names = nil
|
583
608
|
@yaml_encoder = nil
|
584
|
-
|
609
|
+
subclasses.each do |descendant|
|
585
610
|
descendant.send(:reload_schema_from_cache)
|
586
611
|
end
|
587
612
|
end
|
588
613
|
|
589
614
|
# Guesses the table name, but does not decorate it with prefix and suffix information.
|
590
|
-
def undecorated_table_name(
|
591
|
-
table_name =
|
615
|
+
def undecorated_table_name(model_name)
|
616
|
+
table_name = model_name.to_s.demodulize.underscore
|
592
617
|
pluralize_table_names ? table_name.pluralize : table_name
|
593
618
|
end
|
594
619
|
|
@@ -602,9 +627,9 @@ module ActiveRecord
|
|
602
627
|
contained += "_"
|
603
628
|
end
|
604
629
|
|
605
|
-
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(
|
630
|
+
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(model_name)}#{full_table_name_suffix}"
|
606
631
|
else
|
607
|
-
# STI subclasses always use their superclass' table.
|
632
|
+
# STI subclasses always use their superclass's table.
|
608
633
|
base_class.table_name
|
609
634
|
end
|
610
635
|
end
|
@@ -616,32 +641,6 @@ module ActiveRecord
|
|
616
641
|
type
|
617
642
|
end
|
618
643
|
end
|
619
|
-
|
620
|
-
def warn_if_deprecated_type(column)
|
621
|
-
return if attributes_to_define_after_schema_loads.key?(column.name)
|
622
|
-
return unless column.respond_to?(:oid)
|
623
|
-
|
624
|
-
if column.array?
|
625
|
-
array_arguments = ", array: true"
|
626
|
-
else
|
627
|
-
array_arguments = ""
|
628
|
-
end
|
629
|
-
|
630
|
-
if column.sql_type.start_with?("interval")
|
631
|
-
precision_arguments = column.precision.presence && ", precision: #{column.precision}"
|
632
|
-
ActiveSupport::Deprecation.warn(<<~WARNING)
|
633
|
-
The behavior of the `:interval` type will be changing in Rails 7.0
|
634
|
-
to return an `ActiveSupport::Duration` object. If you'd like to keep
|
635
|
-
the old behavior, you can add this line to #{self.name} model:
|
636
|
-
|
637
|
-
attribute :#{column.name}, :string#{precision_arguments}#{array_arguments}
|
638
|
-
|
639
|
-
If you'd like the new behavior today, you can add this line:
|
640
|
-
|
641
|
-
attribute :#{column.name}, :interval#{precision_arguments}#{array_arguments}
|
642
|
-
WARNING
|
643
|
-
end
|
644
|
-
end
|
645
644
|
end
|
646
645
|
end
|
647
646
|
end
|
@@ -5,7 +5,7 @@ require "active_support/core_ext/module/redefine_method"
|
|
5
5
|
require "active_support/core_ext/hash/indifferent_access"
|
6
6
|
|
7
7
|
module ActiveRecord
|
8
|
-
module NestedAttributes
|
8
|
+
module NestedAttributes # :nodoc:
|
9
9
|
class TooManyRecords < ActiveRecordError
|
10
10
|
end
|
11
11
|
|
@@ -180,7 +180,7 @@ module ActiveRecord
|
|
180
180
|
# member.posts.second.title # => '[UPDATED] other post'
|
181
181
|
#
|
182
182
|
# However, the above applies if the parent model is being updated as well.
|
183
|
-
# For example,
|
183
|
+
# For example, if you wanted to create a +member+ named _joe_ and wanted to
|
184
184
|
# update the +posts+ at the same time, that would give an
|
185
185
|
# ActiveRecord::RecordNotFound error.
|
186
186
|
#
|
@@ -245,18 +245,19 @@ module ActiveRecord
|
|
245
245
|
#
|
246
246
|
# === Validating the presence of a parent model
|
247
247
|
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
248
|
+
# The +belongs_to+ association validates the presence of the parent model
|
249
|
+
# by default. You can disable this behavior by specifying <code>optional: true</code>.
|
250
|
+
# This can be used, for example, when conditionally validating the presence
|
251
|
+
# of the parent model:
|
251
252
|
#
|
252
|
-
# class
|
253
|
-
# has_many :
|
254
|
-
# accepts_nested_attributes_for :
|
253
|
+
# class Veterinarian < ActiveRecord::Base
|
254
|
+
# has_many :patients, inverse_of: :veterinarian
|
255
|
+
# accepts_nested_attributes_for :patients
|
255
256
|
# end
|
256
257
|
#
|
257
|
-
# class
|
258
|
-
# belongs_to :
|
259
|
-
#
|
258
|
+
# class Patient < ActiveRecord::Base
|
259
|
+
# belongs_to :veterinarian, inverse_of: :patients, optional: true
|
260
|
+
# validates :veterinarian, presence: true, unless: -> { awaiting_intake }
|
260
261
|
# end
|
261
262
|
#
|
262
263
|
# Note that if you do not specify the +:inverse_of+ option, then
|
@@ -486,7 +487,7 @@ module ActiveRecord
|
|
486
487
|
existing_records = if association.loaded?
|
487
488
|
association.target
|
488
489
|
else
|
489
|
-
attribute_ids = attributes_collection.
|
490
|
+
attribute_ids = attributes_collection.filter_map { |a| a["id"] || a[:id] }
|
490
491
|
attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
|
491
492
|
end
|
492
493
|
|
@@ -26,20 +26,20 @@ module ActiveRecord
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class << self
|
29
|
-
def apply_to(klass)
|
29
|
+
def apply_to(klass) # :nodoc:
|
30
30
|
klasses.push(klass)
|
31
31
|
yield
|
32
32
|
ensure
|
33
33
|
klasses.pop
|
34
34
|
end
|
35
35
|
|
36
|
-
def applied_to?(klass)
|
36
|
+
def applied_to?(klass) # :nodoc:
|
37
37
|
klasses.any? { |k| k >= klass }
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
41
41
|
def klasses
|
42
|
-
|
42
|
+
ActiveSupport::IsolatedExecutionState[:active_record_no_touching_classes] ||= []
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -38,10 +38,6 @@ module ActiveRecord
|
|
38
38
|
false
|
39
39
|
end
|
40
40
|
|
41
|
-
def to_sql
|
42
|
-
""
|
43
|
-
end
|
44
|
-
|
45
41
|
def calculate(operation, _column_name)
|
46
42
|
case operation
|
47
43
|
when :count, :sum
|
@@ -60,8 +56,8 @@ module ActiveRecord
|
|
60
56
|
end
|
61
57
|
|
62
58
|
private
|
63
|
-
def
|
64
|
-
|
59
|
+
def exec_main_query(async: false)
|
60
|
+
[].freeze
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|