---
title: "Rails 6 ActiveRecord::Base.configurations"
description:
  "Rails 6 changed ActiveRecord::Base.configurations result to an object instead
  of a hash"
canonical_url: "https://www.bigbinary.com/blog/rails-6-changed-activerecord-base-configurations-result-to-an-object"
markdown_url: "https://www.bigbinary.com/blog/rails-6-changed-activerecord-base-configurations-result-to-an-object.md"
---

# Rails 6 ActiveRecord::Base.configurations

Rails 6 changed ActiveRecord::Base.configurations result to an object instead of
a hash

- Author: Amit Choudhary
- Published: March 19, 2019
- Categories: Rails 6, Rails

Rails 6 changed the return value of
[ActiveRecord::Base.configurations](https://github.com/rails/rails/pull/33637)
to an object of `ActiveRecord::DatabaseConfigurations`. Before Rails 6,
[ActiveRecord::Base.configurations](https://api.rubyonrails.org/v5.2.2/classes/ActiveRecord/Core.html#method-c-configurations)
returned a hash with all the database configurations. We can call `to_h` on the
object of `ActiveRecord::DatabaseConfigurations` to get a hash.

A method named [configs_for](https://github.com/rails/rails/pull/33637) has also
been added on to fetch configurations for a particular environment.

#### Rails 5.2

```ruby
>> ActiveRecord::Base.configurations

=> {"development"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}, "test"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}, "production"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}}
```

#### Rails 6.0.0.beta2

```ruby
>> ActiveRecord::Base.configurations

=> #<ActiveRecord::DatabaseConfigurations:0x00007fc18274f9f0 @configurations=[#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fc18274f680 @env_name="development", @spec_name="primary", @config={"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}>, #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fc18274f608 @env_name="test", @spec_name="primary", @config={"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}>, #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fc18274f590 @env_name="production", @spec_name="primary", @config={"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}>]>

>> ActiveRecord::Base.configurations.to_h

=> {"development"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}, "test"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}, "production"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}}

>> ActiveRecord::Base.configurations['development']

=> {"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}

>> ActiveRecord::Base.configurations.configs_for(env_name: "development")

=> [#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fc18274f680 @env_name="development", @spec_name="primary", @config={"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}>]
```

Here is the relevant [pull request](https://github.com/rails/rails/pull/33637).

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-changed-activerecord-base-configurations-result-to-an-object)
