1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/connection_adapters
eileencodes 4144746d33
Expose primary_abstract_class public API
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>
2021-01-27 15:01:59 -05:00
..
adapter_leasing_test.rb Fix preventing writes for ApplicationRecord 2021-01-06 09:19:19 -05:00
connection_handler_test.rb Module#const_set is a public method 2020-09-15 17:19:37 +09:00
connection_handlers_multi_db_test.rb Remove database kwarg from connected_to 2020-11-03 16:28:11 -05:00
connection_handlers_multi_pool_config_test.rb Add helper method for resetting connection handlers in tests 2020-08-10 10:20:12 -04:00
connection_handlers_sharding_db_test.rb Implement granular role and shard swapping 2020-10-28 15:11:35 -04:00
connection_swapping_nested_test.rb Expose primary_abstract_class public API 2021-01-27 15:01:59 -05:00
legacy_connection_handlers_multi_db_test.rb Remove database kwarg from connected_to 2020-11-03 16:28:11 -05:00
legacy_connection_handlers_sharding_db_test.rb Don't allow granular swapping for shards in legacy 2020-10-29 08:58:02 -04:00
merge_and_resolve_default_url_config_test.rb Connection specification now passes the "url" key to the adapter 2021-01-22 20:24:33 +00:00
mysql_type_lookup_test.rb MySQL: Fix schema dumping enum and set columns correctly 2019-07-05 18:42:41 +09:00
schema_cache_test.rb Update SchemaCacheTest#schema_dump_path 2020-04-14 10:43:47 -04:00
type_lookup_test.rb Enable Layout/EmptyLinesAroundAccessModifier cop 2019-06-13 12:00:45 +09:00