Module: ActiveRecord
Overview
Constant Summary
-
UnknownAttributeError =
Raised when unknown attributes are supplied via mass assignment.
ActiveModel::UnknownAttributeError
Class Attribute Summary
- .db_warnings_action=(action) writeonly
-
.default_timezone=(default_timezone)
writeonly
Determines whether to use
Time.utc
(using:utc
) orTime.local
(using:local
) when pulling dates and times from the database. -
.global_executor_concurrency=(global_executor_concurrency)
rw
Set the .global_executor_concurrency.
- .legacy_connection_handling=(_) writeonly
- .marshalling_format_version rw
- .marshalling_format_version=(value) rw
- .suppress_multiple_database_warning rw
- .suppress_multiple_database_warning=(value) rw
Class Method Summary
-
.disconnect_all!
Explicitly closes all database connections in all pools.
- .eager_load!
-
.gem_version
Returns the currently loaded version of Active Record as a
Gem::Version
. -
.version
Returns the currently loaded version of Active Record as a
Gem::Version
.
::ActiveSupport::Autoload
- Extended
Instance Attribute Summary
-
#action_on_strict_loading_violation
rw
:singleton-method: Set the application to log or raise when an association violates strict loading.
- #allow_deprecated_singular_associations_name rw
- #application_record_class rw
-
#async_query_executor
rw
Sets the async_query_executor for an application.
- #before_committed_on_all_records rw
- #belongs_to_required_validates_foreign_key rw
- #commit_transaction_on_non_local_return rw
-
#db_warnings_action
readonly
The action to take when database query produces warning.
-
#db_warnings_ignore
rw
Specify allowlist of database warnings.
- #default_timezone readonly
- #disable_prepared_statements rw
-
#dump_schema_after_migration
rw
:singleton-method: Specify whether schema dump should happen at the end of the bin/rails db:migrate command.
-
#dump_schemas
rw
:singleton-method: Specifies which database schemas to dump when calling db:schema:dump.
-
#error_on_ignored_order
rw
:singleton-method: Specifies if an error should be raised if the query has an order being ignored when doing batch queries.
-
#generate_secure_token_on
rw
:singleton-method: Controls when to generate a value for
has_secure_token
declarations. - #index_nested_attribute_errors rw
-
#lazily_load_schema_cache
rw
Lazily load the schema cache.
- #maintain_test_schema rw
-
#migration_strategy
rw
:singleton-method: Specify strategy to use for executing migrations.
- #query_transformers rw
-
#queues
rw
:singleton-method:
-
#raise_int_wider_than_64bit
rw
:singleton-method: Application configurable boolean that denotes whether or not to raise an exception when the PostgreSQLAdapter is provided with an integer that is wider than signed 64bit representation.
- #raise_on_assign_to_attr_readonly rw
- #reading_role rw
- #run_after_transaction_callbacks_in_order_defined rw
-
#schema_cache_ignored_tables
rw
A list of tables or regex’s to match tables to ignore when dumping the schema cache.
-
#schema_format
rw
:singleton-method: Specifies the format to use when dumping the database schema with Rails’ Rakefile.
-
#timestamped_migrations
rw
:singleton-method: Specify whether or not to use timestamps for migration versions.
-
#use_yaml_unsafe_load
rw
:singleton-method: Application configurable boolean that instructs the YAML Coder to use an unsafe load if set to true.
-
#verbose_query_logs
rw
:singleton-method:
-
#verify_foreign_keys_for_fixtures
rw
:singleton-method: If true,
::Rails
will verify all foreign keys in the database after loading fixtures. -
#warn_on_records_fetched_greater_than
rw
:singleton-method: Specify a threshold for the size of query result sets.
- #writing_role rw
-
#yaml_column_permitted_classes
rw
:singleton-method: Application configurable array that provides additional permitted classes to Psych safe_load in the YAML Coder.
Class Attribute Details
.db_warnings_action=(action) (writeonly)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 211
def self.db_warnings_action=(action) @db_warnings_action = case action when :ignore nil when :log ->(warning) do = "[#{warning.class}] #{warning.}" += " (#{warning.code})" if warning.code ActiveRecord::Base.logger.warn( ) end when :raise ->(warning) { raise warning } when :report ->(warning) { Rails.error.report(warning, handled: true) } when Proc action else raise ArgumentError, "db_warnings_action must be one of :ignore, :log, :raise, :report, or a custom proc." end end
.default_timezone=(default_timezone) (writeonly)
Determines whether to use Time.utc
(using :utc
) or Time.local
(using :local
) when pulling dates and times from the database. This is set to :utc
by default.
# File 'activerecord/lib/active_record.rb', line 196
def self.default_timezone=(default_timezone) unless %i(local utc).include?(default_timezone) raise ArgumentError, "default_timezone must be either :utc (default) or :local." end @default_timezone = default_timezone end
.global_executor_concurrency=(global_executor_concurrency) (rw)
Set the .global_executor_concurrency. This configuration value can only be used with the global thread pool async query executor.
# File 'activerecord/lib/active_record.rb', line 278
def self.global_executor_concurrency=(global_executor_concurrency) if self.async_query_executor.nil? || self.async_query_executor == :multi_thread_pool raise ArgumentError, "`global_executor_concurrency` cannot be set when the executor is nil or set to `:multi_thread_pool`. For multiple thread pools, please set the concurrency in your database configuration." end @global_executor_concurrency = global_executor_concurrency end
.legacy_connection_handling=(_) (writeonly)
# File 'activerecord/lib/active_record.rb', line 245
def self.legacy_connection_handling=(_) raise ArgumentError, <<~MSG.squish The `legacy_connection_handling` setter was deprecated in 7.0 and removed in 7.1, but is still defined in your configuration. Please remove this call as it no longer has any effect." MSG end
.marshalling_format_version (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 457
def self.marshalling_format_version Marshalling.format_version end
.marshalling_format_version=(value) (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 461
def self.marshalling_format_version=(value) Marshalling.format_version = value end
.suppress_multiple_database_warning (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 395
def self.suppress_multiple_database_warning ActiveRecord.deprecator.warn(<<-MSG.squish) config.active_record.suppress_multiple_database_warning is deprecated and will be removed in Rails 7.2. It no longer has any effect and should be removed from the configuration file. MSG end
.suppress_multiple_database_warning=(value) (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 402
def self.suppress_multiple_database_warning=(value) ActiveRecord.deprecator.warn(<<-MSG.squish) config.active_record.suppress_multiple_database_warning= is deprecated and will be removed in Rails 7.2. It no longer has any effect and should be removed from the configuration file. MSG end
Class Method Details
.disconnect_all!
Explicitly closes all database connections in all pools.
# File 'activerecord/lib/active_record.rb', line 476
def self.disconnect_all! ConnectionAdapters::PoolConfig.disconnect_all! end
.eager_load!
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 465
def self.eager_load! super ActiveRecord::Locking.eager_load! ActiveRecord::Scoping.eager_load! ActiveRecord::Associations.eager_load! ActiveRecord::AttributeMethods.eager_load! ActiveRecord::ConnectionAdapters.eager_load! ActiveRecord::Encryption.eager_load! end
.gem_version
Returns the currently loaded version of Active Record as a Gem::Version
.
.version
Returns the currently loaded version of Active Record as a Gem::Version
.
# File 'activerecord/lib/active_record/version.rb', line 7
def self.version gem_version end
Instance Attribute Details
#action_on_strict_loading_violation (rw)
:singleton-method: Set the application to log or raise when an association violates strict loading. Defaults to :raise
.
# File 'activerecord/lib/active_record.rb', line 342
singleton_class.attr_accessor :action_on_strict_loading_violation
#allow_deprecated_singular_associations_name (rw)
# File 'activerecord/lib/active_record.rb', line 422
singleton_class.attr_accessor :allow_deprecated_singular_associations_name
#application_record_class (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 335
singleton_class.attr_accessor :application_record_class
#async_query_executor (rw)
Sets the async_query_executor for an application. By default the thread pool executor set to nil
which will not run queries in the background. Applications must configure a thread pool executor to use this feature. Options are:
* nil - Does not initialize a thread pool executor. Any async calls will be
run in the foreground.
* :global_thread_pool - Initializes a single {Concurrent::ThreadPoolExecutor}
that uses the {async_query_concurrency} for the {max_threads} value.
* :multi_thread_pool - Initializes a {Concurrent::ThreadPoolExecutor} for each
database connection. The initializer values are defined in the configuration hash.
# File 'activerecord/lib/active_record.rb', line 263
singleton_class.attr_accessor :async_query_executor
#before_committed_on_all_records (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 317
singleton_class.attr_accessor :before_committed_on_all_records
#belongs_to_required_validates_foreign_key (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 314
singleton_class.attr_accessor :belongs_to_required_validates_foreign_key
#commit_transaction_on_non_local_return (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 323
singleton_class.attr_accessor :commit_transaction_on_non_local_return
#db_warnings_action (readonly)
The action to take when database query produces warning. Must be one of :ignore
, :log
, :raise
, :report
, or a custom proc. The default is :ignore
.
# File 'activerecord/lib/active_record.rb', line 209
singleton_class.attr_reader :db_warnings_action
#db_warnings_ignore (rw)
Specify allowlist of database warnings.
# File 'activerecord/lib/active_record.rb', line 236
singleton_class.attr_accessor :db_warnings_ignore
#default_timezone (readonly)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 192
singleton_class.attr_reader :default_timezone
#disable_prepared_statements (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 177
singleton_class.attr_accessor :disable_prepared_statements
#dump_schema_after_migration (rw)
:singleton-method: Specify whether schema dump should happen at the end of the bin/rails db:migrate command. This is true by default, which is useful for the development environment. This should ideally be false in the production environment where dumping schema is rarely needed.
# File 'activerecord/lib/active_record.rb', line 382
singleton_class.attr_accessor :dump_schema_after_migration
#dump_schemas (rw)
:singleton-method: Specifies which database schemas to dump when calling db:schema:dump. If the value is :schema_search_path
(the default), any schemas listed in schema_search_path are dumped. Use :all
to dump all schemas regardless of schema_search_path, or a string of comma separated schemas for a custom list.
# File 'activerecord/lib/active_record.rb', line 392
singleton_class.attr_accessor :dump_schemas
#error_on_ignored_order (rw)
:singleton-method: Specifies if an error should be raised if the query has an order being ignored when doing batch queries. Useful in applications where the scope being ignored is error-worthy, rather than a warning.
# File 'activerecord/lib/active_record.rb', line 361
singleton_class.attr_accessor :error_on_ignored_order
#generate_secure_token_on (rw)
:singleton-method: Controls when to generate a value for has_secure_token
declarations. Defaults to :create
.
# File 'activerecord/lib/active_record.rb', line 454
singleton_class.attr_accessor :generate_secure_token_on
#index_nested_attribute_errors (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 290
singleton_class.attr_accessor :index_nested_attribute_errors
#lazily_load_schema_cache (rw)
Lazily load the schema cache. This option will load the schema cache when a connection is established rather than on boot. If set, config.active_record.use_schema_cache_dump
will be set to false.
# File 'activerecord/lib/active_record.rb', line 183
singleton_class.attr_accessor :lazily_load_schema_cache
#maintain_test_schema (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 308
singleton_class.attr_accessor :maintain_test_schema
#migration_strategy (rw)
:singleton-method: Specify strategy to use for executing migrations.
# File 'activerecord/lib/active_record.rb', line 373
singleton_class.attr_accessor :migration_strategy
#query_transformers (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 425
singleton_class.attr_accessor :query_transformers
#queues (rw)
:singleton-method:
Specifies the names of the queues used by background jobs.
# File 'activerecord/lib/active_record.rb', line 305
singleton_class.attr_accessor :queues
#raise_int_wider_than_64bit (rw)
:singleton-method: Application configurable boolean that denotes whether or not to raise an exception when the PostgreSQLAdapter is provided with an integer that is wider than signed 64bit representation
# File 'activerecord/lib/active_record.rb', line 440
singleton_class.attr_accessor :raise_int_wider_than_64bit
#raise_on_assign_to_attr_readonly (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 311
singleton_class.attr_accessor :raise_on_assign_to_attr_readonly
#reading_role (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 242
singleton_class.attr_accessor :reading_role
#run_after_transaction_callbacks_in_order_defined (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 320
singleton_class.attr_accessor :run_after_transaction_callbacks_in_order_defined
#schema_cache_ignored_tables (rw)
A list of tables or regex’s to match tables to ignore when dumping the schema cache. For example if this is set to [/^_/]
the schema cache will not dump tables named with an underscore.
# File 'activerecord/lib/active_record.rb', line 189
singleton_class.attr_accessor :schema_cache_ignored_tables
#schema_format (rw)
:singleton-method: Specifies the format to use when dumping the database schema with Rails’ Rakefile. If :sql
, the schema is dumped as (potentially database- specific) SQL statements. If :ruby
, the schema is dumped as an ::ActiveRecord::Schema
file which can be loaded into any database that supports migrations. Use :ruby
if you want to have different database adapters for, e.g., your development and test environments.
# File 'activerecord/lib/active_record.rb', line 353
singleton_class.attr_accessor :schema_format
#timestamped_migrations (rw)
:singleton-method: Specify whether or not to use timestamps for migration versions
# File 'activerecord/lib/active_record.rb', line 367
singleton_class.attr_accessor :
#use_yaml_unsafe_load (rw)
:singleton-method: Application configurable boolean that instructs the YAML Coder to use an unsafe load if set to true.
# File 'activerecord/lib/active_record.rb', line 432
singleton_class.attr_accessor :use_yaml_unsafe_load
#verbose_query_logs (rw)
:singleton-method:
Specifies if the methods calling database queries should be logged below their relevant queries. Defaults to false.
# File 'activerecord/lib/active_record.rb', line 298
singleton_class.attr_accessor :verbose_query_logs
#verify_foreign_keys_for_fixtures (rw)
:singleton-method: If true, ::Rails
will verify all foreign keys in the database after loading fixtures. An error will be raised if there are any foreign key violations, indicating incorrectly written fixtures. Supported by PostgreSQL and SQLite.
# File 'activerecord/lib/active_record.rb', line 415
singleton_class.attr_accessor :verify_foreign_keys_for_fixtures
#warn_on_records_fetched_greater_than (rw)
:singleton-method: Specify a threshold for the size of query result sets. If the number of records in the set exceeds the threshold, a warning is logged. This can be used to identify queries which load thousands of records and potentially cause memory bloat.
# File 'activerecord/lib/active_record.rb', line 332
singleton_class.attr_accessor :warn_on_records_fetched_greater_than
#writing_role (rw)
[ GitHub ]# File 'activerecord/lib/active_record.rb', line 239
singleton_class.attr_accessor :writing_role
#yaml_column_permitted_classes (rw)
:singleton-method: Application configurable array that provides additional permitted classes to Psych safe_load in the YAML Coder
# File 'activerecord/lib/active_record.rb', line 447
singleton_class.attr_accessor :yaml_column_permitted_classes