mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
4144746d33
Previously Rails was treating `ApplicationRecord` as special in the `primary_class?` check. The reason we need to treat it differtently than other connection classes is that `ActiveRecord::Base` will establish a connection to the primary database on boot. The established connection is to your primary database, or the first database defined in your configuration. We need to do this so that 2 connections aren't opened to the same database since `ActiveRecord::Base` and `AppliationRecord` are different classes, on connection the connection_speicification_name would be different. However, there is no guarantee that an application is using `ApplicationRecord` as it's primary abstract class. This exposes a public method for setting a class to a `primary_abstract_class` like this: ``` class PrimaryApplicationRecord < ActiveRecord::Base self.primary_abstract_class end ``` Calling `primary_abstract_class` will automatically set `self.abstract_class = true`. This change is backwards compatible because we weren't supporting multiple application records previously, and if you had an `ApplicationRecord` we assumed that was the primary class. This change continues to assume that `ApplicationRecord` is your primary class. You only need to set `primary_abstract_class` if your application record is not ApplicationRecord and you're using multiple databases. Co-authored-by: John Crepezzi <john.crepezzi@gmail.com> |
||
---|---|---|
.. | ||
adapter_leasing_test.rb | ||
connection_handler_test.rb | ||
connection_handlers_multi_db_test.rb | ||
connection_handlers_multi_pool_config_test.rb | ||
connection_handlers_sharding_db_test.rb | ||
connection_swapping_nested_test.rb | ||
legacy_connection_handlers_multi_db_test.rb | ||
legacy_connection_handlers_sharding_db_test.rb | ||
merge_and_resolve_default_url_config_test.rb | ||
mysql_type_lookup_test.rb | ||
schema_cache_test.rb | ||
type_lookup_test.rb |