PostgreSQL: support custom enum types
Something I've seen on many Rails + PostgreSQL apps is that the only reason `structure.sql` is used instead of `schema.rb` is to support custom [enum types](https://www.postgresql.org/docs/current/datatype-enum.html). Enum types are great for type integrity and they work well with [`ActiveRecord::Enum`](https://api.rubyonrails.org/classes/ActiveRecord/Enum.html). And schema.rb is much easier to use than structure.sql. It would be great if more PostgreSQL projects could use schema.rb. To enable that, this PR adds native support for PostgreSQL enums in schema.rb.
In migrations, you can now use `create_enum` to add a new enum type, and `t.enum` to add a column:
```ruby
def up
# note that enums cannot be dropped
create_enum :mood, ["happy", "sad"]
change_table :cats do |t|
t.enum :current_mood, enum_type: "mood", default: "happy", null: false
end
end
```
The enum definitions and enum columns will be presented in schema.rb, so you can load them into a test database and they'll work correctly.
-------------------------------
It's worth noting again that this is *not* compatible with other database engines. So this will not work with `rails db:system:change` (or the equivalent manual process). My assumption is that this is a fairly unlikely thing to happen midway through a project - as opposed to when the app is first spun up - so it's safe to assume that once you've dug into using enums you probably aren't going to switch databases on a whim.
For what it's worth, the MySQL adapter also supports enums (https://github.com/rails/rails/blob/main/activerecord/test/cases/adapters/mysql2/enum_test.rb) but the syntax doesn't look easy to translate (I also don't have much MySQL experience so don't really want to wade into this).
2021-03-28 19:48:48 -04:00
* PostgreSQL: support custom enum types
In migrations, use `create_enum` to add a new enum type, and `t.enum` to add a column.
```ruby
def up
create_enum :mood, ["happy", "sad"]
change_table :cats do |t|
t.enum :current_mood, enum_type: "mood", default: "happy", null: false
end
end
```
Enums will be presented correctly in `schema.rb` . Note that this is only supported by
the PostgreSQL adapter.
*Alex Ghiculescu*
2021-09-13 10:48:55 -04:00
* Avoid COMMENT statements in PostgreSQL structure dumps
COMMENT statements are now omitted from the output of `db:structure:dump` when using PostgreSQL >= 11.
This allows loading the dump without a pgsql superuser account.
Fixes #36816 , #43107 .
*Janosch Müller*
2020-05-20 10:24:00 -04:00
* Add support for generated columns in PostgreSQL adapter
Generated columns are supported since version 12.0 of PostgreSQL. This adds
support of those to the PostgreSQL adapter.
```ruby
create_table :users do |t|
t.string :name
2021-04-06 13:04:50 -04:00
t.virtual :name_upcased, type: :string, as: 'upper(name)', stored: true
2020-05-20 10:24:00 -04:00
end
```
*Michał Begejowicz*
2021-09-16 10:04:33 -04:00
2021-09-15 18:22:51 -04:00
## Rails 7.0.0.alpha2 (September 15, 2021) ##
* No changes.
2021-09-15 17:55:08 -04:00
## Rails 7.0.0.alpha1 (September 15, 2021) ##
2021-09-10 15:19:46 -04:00
* Remove warning when overwriting existing scopes
Removes the following unnecessary warning message that appeared when overwriting existing scopes
```
Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes
```
2021-09-14 22:57:23 -04:00
*Weston Ganger*
2021-08-10 17:31:36 -04:00
* Use full precision for `updated_at` in `insert_all` /`upsert_all`
`CURRENT_TIMESTAMP` provides differing precision depending on the database,
and not all databases support explicitly specifying additional precision.
Instead, we delegate to the new `connection.high_precision_current_timestamp`
for the SQL to produce a high precision timestamp on the current database.
Fixes #42992
*Sam Bostock*
2021-08-22 09:28:21 -04:00
* Add ssl support for postgresql database tasks
Add `PGSSLMODE` , `PGSSLCERT` , `PGSSLKEY` and `PGSSLROOTCERT` to pg_env from database config
when running postgresql database tasks.
```yaml
# config/database.yml
production:
sslmode: verify-full
sslcert: client.crt
sslkey: client.key
sslrootcert: ca.crt
```
Environment variables
```
PGSSLMODE=verify-full
PGSSLCERT=client.crt
PGSSLKEY=client.key
PGSSLROOTCERT=ca.crt
```
Fixes #42994
*Michael Bayucot*
2021-09-09 11:41:14 -04:00
* Avoid scoping update callbacks in `ActiveRecord::Relation#update!` .
Making it consistent with how scoping is applied only to the query in `ActiveRecord::Relation#update`
and not also to the callbacks from the update itself.
*Dylan Thacker-Smith*
2021-09-01 10:18:55 -04:00
* Fix 2 cases that inferred polymorphic class from the association's `foreign_type`
using `String#constantize` instead of the model's `polymorphic_class_for` .
When updating a polymorphic association, the old `foreign_type` was not inferred correctly when:
1. `touch` ing the previously associated record
2. updating the previously associated record's `counter_cache`
*Jimmy Bourassa*
2021-08-16 08:52:18 -04:00
* Add config option for ignoring tables when dumping the schema cache.
Applications can now be configured to ignore certain tables when dumping the schema cache.
The configuration option can table an array of tables:
```ruby
config.active_record.schema_cache_ignored_tables = ["ignored_table", "another_ignored_table"]
```
Or a regex:
```ruby
config.active_record.schema_cache_ignored_tables = [/^_/]
```
*Eileen M. Uchitelle*
2021-08-25 10:01:07 -04:00
* Make schema cache methods return consistent results.
2021-08-27 21:32:31 -04:00
Previously the schema cache methods `primary_keys` , `columns` , `columns_hash` , and `indexes`
2021-08-25 10:01:07 -04:00
would behave differently than one another when a table didn't exist and differently across
2021-08-26 14:49:26 -04:00
database adapters. This change unifies the behavior so each method behaves the same regardless
of adapter.
The behavior now is:
`columns` : (unchanged) raises a db error if the table does not exist
`columns_hash` : (unchanged) raises a db error if the table does not exist
`primary_keys` : (unchanged) returns `nil` if the table does not exist
`indexes` : (changed for mysql2) returns `[]` if the table does not exist
2021-08-25 10:01:07 -04:00
*Eileen M. Uchitelle*
2021-08-19 03:12:25 -04:00
* Reestablish connection to previous database after after running `db:schema:load:name`
After running `db:schema:load:name` the previous connection is restored.
*Jacopo Beschi*
2021-07-15 14:49:29 -04:00
* Add database config option `database_tasks`
If you would like to connect to an external database without any database
2021-08-16 23:41:08 -04:00
management tasks such as schema management, migrations, seeds, etc. you can set
2021-07-15 14:49:29 -04:00
the per database config option `database_tasks: false`
```yaml
# config/database.yml
production:
primary:
database: my_database
adapter: mysql2
animals:
database: my_animals_database
adapter: mysql2
database_tasks: false
```
2021-09-10 15:19:46 -04:00
*Weston Ganger*
2021-08-11 03:54:32 -04:00
* Fix `ActiveRecord::InternalMetadata` to not be broken by `config.active_record.record_timestamps = false`
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
various DB management tasks.
Fixes #42983
2021-03-08 05:51:29 -05:00
* Add `ActiveRecord::QueryLogs` .
Configurable tags can be automatically added to all SQL queries generated by Active Record.
```ruby
# config/application.rb
module MyApp
class Application < Rails::Application
config.active_record.query_log_tags_enabled = true
end
end
```
By default the application, controller and action details are added to the query tags:
```ruby
class BooksController < ApplicationController
def index
@books = Book.all
end
end
```
```ruby
GET /books
# SELECT * FROM books /*application:MyApp;controller:books;action:index*/
```
Custom tags containing static values and Procs can be defined in the application configuration:
```ruby
config.active_record.query_log_tags = [
:application,
:controller,
:action,
{
custom_static: "foo",
custom_dynamic: -> { Time.now }
}
]
```
*Keeran Raj Hawoldar* , *Eileen M. Uchitelle* , *Kasper Timm Hansen*
2021-08-03 17:59:39 -04:00
* Added support for multiple databases to `rails db:setup` and `rails db:reset` .
*Ryan Hall*
2021-04-05 08:48:55 -04:00
* Add `ActiveRecord::Relation#structurally_compatible?` .
Adds a query method by which a user can tell if the relation that they're
about to use for `#or` or `#and` is structurally compatible with the
receiver.
*Kevin Newton*
Add `ActiveRecord::QueryMethods#in_order_of`.
This allows you to specify an explicit order that you'd like records
returned in based on a SQL expression. By default, this will be accomplished
using a case statement, as in:
```ruby
Post.in_order_of(:id, [3, 5, 1])
```
will generate the SQL:
```sql
SELECT "posts".* FROM "posts" ORDER BY CASE "posts"."id" WHEN 3 THEN 1 WHEN 5 THEN 2 WHEN 1 THEN 3 ELSE 4 END ASC
```
However, because this functionality is built into MySQL in the form of the
`FIELD` function, that connection adapter will generate the following SQL
instead:
```sql
SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
```
*Kevin Newton*
2021-04-23 10:13:09 -04:00
* Add `ActiveRecord::QueryMethods#in_order_of` .
This allows you to specify an explicit order that you'd like records
returned in based on a SQL expression. By default, this will be accomplished
using a case statement, as in:
```ruby
Post.in_order_of(:id, [3, 5, 1])
```
will generate the SQL:
```sql
SELECT "posts".* FROM "posts" ORDER BY CASE "posts"."id" WHEN 3 THEN 1 WHEN 5 THEN 2 WHEN 1 THEN 3 ELSE 4 END ASC
```
However, because this functionality is built into MySQL in the form of the
`FIELD` function, that connection adapter will generate the following SQL
instead:
```sql
SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
```
*Kevin Newton*
2021-08-07 12:53:10 -04:00
* Fix `eager_loading?` when ordering with `Symbol` .
2021-07-30 04:02:11 -04:00
`eager_loading?` is triggered correctly when using `order` with symbols.
```ruby
scope = Post.includes(:comments).order(:"comments.label")
=> true
```
*Jacopo Beschi*
2021-07-10 23:09:34 -04:00
* Two change tracking methods are added for `belongs_to` associations.
The `association_changed?` method (assuming an association named `:association` ) returns true
if a different associated object has been assigned and the foreign key will be updated in the
next save.
The `association_previously_changed?` method returns true if the previous save updated the
association to reference a different associated object.
*George Claghorn*
2021-07-20 21:08:08 -04:00
* Add option to disable schema dump per-database.
2021-07-15 13:58:52 -04:00
Dumping the schema is on by default for all databases in an application. To turn it off for a
specific database use the `schema_dump` option:
```yaml
# config/database.yml
production:
schema_dump: false
```
*Luis Vasconcellos* , *Eileen M. Uchitelle*
2021-08-07 12:53:10 -04:00
* Fix `eager_loading?` when ordering with `Hash` syntax.
2021-07-14 05:08:58 -04:00
`eager_loading?` is triggered correctly when using `order` with hash syntax
on an outer table.
```ruby
Post.includes(:comments).order({ "comments.label": :ASC }).eager_loading?
2021-07-20 21:08:08 -04:00
# => true
2021-07-14 05:08:58 -04:00
```
*Jacopo Beschi*
2021-07-13 15:02:38 -04:00
* Move the forcing of clear text encoding to the `ActiveRecord::Encryption::Encryptor` .
Fixes #42699 .
*J Smith*
2021-07-13 04:46:56 -04:00
* `partial_inserts` is now disabled by default in new apps.
This will be the default for new apps in Rails 7. To opt in:
```ruby
2021-07-21 03:12:36 -04:00
config.active_record.partial_inserts = true
2021-07-13 04:46:56 -04:00
```
If a migration remove the default value of a column, this option
would cause old processes to no longer be able to create new records.
If you need to remove a column, you should first use `ignored_columns`
to stop using it.
*Jean Boussier*
2021-07-12 11:23:58 -04:00
* Rails can now verify foreign keys after loading fixtures in tests.
This will be the default for new apps in Rails 7. To opt in:
2021-07-13 04:46:56 -04:00
2021-07-12 11:23:58 -04:00
```ruby
config.active_record.verify_foreign_keys_for_fixtures = true
```
2021-07-13 04:46:56 -04:00
2021-07-12 11:23:58 -04:00
Tests will not run if there is a foreign key constraint violation in your fixture data.
The feature is supported by SQLite and PostgreSQL, other adapters can also add support for it.
*Alex Ghiculescu*
2021-06-25 08:52:26 -04:00
* Clear cached `has_one` association after setting `belongs_to` association to `nil` .
After setting a `belongs_to` relation to `nil` and updating an unrelated attribute on the owner,
the owner should still return `nil` on the `has_one` relation.
Fixes #42597 .
*Michiel de Mare*
2021-03-22 05:25:49 -04:00
* OpenSSL constants are now used for Digest computations.
*Dirkjan Bussink*
2021-06-27 06:23:12 -04:00
* Adds support for `if_not_exists` to `add_foreign_key` and `if_exists` to `remove_foreign_key` .
Applications can set their migrations to ignore exceptions raised when adding a foreign key
that already exists or when removing a foreign key that does not exist.
Example Usage:
```ruby
class AddAuthorsForeignKeyToArticles < ActiveRecord::Migration [ 7 . 0 ]
def change
add_foreign_key :articles, :authors, if_not_exists: true
end
end
```
```ruby
class RemoveAuthorsForeignKeyFromArticles < ActiveRecord::Migration [ 7 . 0 ]
def change
remove_foreign_key :articles, :authors, if_exists: true
end
end
```
*Roberto Miranda*
2021-07-20 21:08:08 -04:00
* Prevent polluting ENV during postgresql structure dump/load.
2021-06-24 02:14:36 -04:00
Some configuration parameters were provided to pg_dump / psql via
environment variables which persisted beyond the command being run, and may
have caused subsequent commands and connections to fail. Tasks running
across multiple postgresql databases like `rails db:test:prepare` may have
been affected.
*Samuel Cochran*
2021-07-20 21:08:08 -04:00
* Set precision 6 by default for `datetime` columns.
2021-05-26 11:12:39 -04:00
By default, datetime columns will have microseconds precision instead of seconds precision.
*Roberto Miranda*
2021-07-20 21:08:08 -04:00
* Allow preloading of associations with instance dependent scopes.
2021-06-21 16:34:09 -04:00
*John Hawthorn* , *John Crepezzi* , *Adam Hess* , *Eileen M. Uchitelle* , *Dinah Shi*
2021-06-16 17:17:34 -04:00
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError` .
*Jamie McCarthy*
2021-06-17 06:30:35 -04:00
* Active Record Encryption will now encode values as UTF-8 when using deterministic
encryption. The encoding is part of the encrypted payload, so different encodings for
different values result in different ciphertexts. This can break unique constraints and
queries.
The new behavior is configurable via `active_record.encryption.forced_encoding_for_deterministic_encryption`
that is `Encoding::UTF_8` by default. It can be disabled by setting it to `nil` .
*Jorge Manrubia*
2021-07-13 07:31:11 -04:00
* The MySQL adapter now cast numbers and booleans bind parameters to string for safety reasons.
2021-06-10 05:34:55 -04:00
2021-07-13 07:31:11 -04:00
When comparing a string and a number in a query, MySQL converts the string to a number. So for
2021-06-10 05:34:55 -04:00
instance `"foo" = 0` , will implicitly cast `"foo"` to `0` and will evaluate to `TRUE` which can
lead to security vulnerabilities.
Active Record already protect against that vulnerability when it knows the type of the column
being compared, however until now it was still vulnerable when using bind parameters:
2021-06-10 19:12:48 -04:00
2021-06-10 05:34:55 -04:00
```ruby
User.where("login_token = ?", 0).first
```
Would perform:
```sql
SELECT * FROM `users` WHERE `login_token` = 0 LIMIT 1;
```
Now it will perform:
```sql
SELECT * FROM `users` WHERE `login_token` = '0' LIMIT 1;
```
*Jean Boussier*
2021-06-15 04:43:30 -04:00
* Fixture configurations (`_fixture`) are now strictly validated.
If an error will be raised if that entry contains unknown keys while previously it
would silently have no effects.
*Jean Boussier*
2021-06-10 08:06:59 -04:00
* Add `ActiveRecord::Base.update!` that works like `ActiveRecord::Base.update` but raises exceptions.
This allows for the same behavior as the instance method `#update!` at a class level.
```ruby
Person.update!(:all, state: "confirmed")
```
2021-06-10 06:39:45 -04:00
*Dorian Marié*
2021-07-20 21:08:08 -04:00
* Add `ActiveRecord::Base#attributes_for_database` .
2021-06-06 23:49:43 -04:00
Returns attributes with values for assignment to the database.
*Chris Salzberg*
2021-07-20 21:08:08 -04:00
* Use an empty query to check if the PostgreSQL connection is still active.
2021-06-02 08:55:54 -04:00
An empty query is faster than `SELECT 1` .
*Heinrich Lee Yu*
2021-07-20 21:08:08 -04:00
* Add `ActiveRecord::Base#previously_persisted?` .
2021-06-04 07:02:54 -04:00
Returns `true` if the object has been previously persisted but now it has been deleted.
2021-06-02 07:02:50 -04:00
* Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates` .
This allows to have a different behavior on update and create.
*Jean Boussier*
2021-05-19 05:22:13 -04:00
* Fix compatibility with `psych >= 4` .
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load` . To preserve compatibility
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
*Jean Boussier*
2021-05-17 07:55:15 -04:00
* `ActiveRecord::Base.logger` is now a `class_attribute` .
This means it can no longer be accessed directly through `@@logger` , and that setting `logger =`
on a subclass won't change the parent's logger.
*Jean Boussier*
2021-05-17 21:07:23 -04:00
* Add `.asc.nulls_first` for all databases. Unfortunately MySQL still doesn't like `nulls_last` .
*Keenan Brock*
2021-05-04 10:34:42 -04:00
* Improve performance of `one?` and `many?` by limiting the generated count query to 2 results.
*Gonzalo Riestra*
2021-05-13 08:38:46 -04:00
* Don't check type when using `if_not_exists` on `add_column` .
Previously, if a migration called `add_column` with the `if_not_exists` option set to true
the `column_exists?` check would look for a column with the same name and type as the migration.
Recently it was discovered that the type passed to the migration is not always the same type
as the column after migration. For example a column set to `:mediumblob` in the migration will
be casted to `binary` when calling `column.type` . Since there is no straightforward way to cast
the type to the database type without running the migration, we opted to drop the type check from
`add_column` . This means that migrations adding a duplicate column with a different type will no
longer raise an error.
*Eileen M. Uchitelle*
2021-07-20 21:08:08 -04:00
* Log a warning message when running SQLite in production.
2021-05-03 09:18:43 -04:00
Using SQLite in production ENV is generally discouraged. SQLite is also the default adapter
in a new Rails application.
For the above reasons log a warning message when running SQLite in production.
The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false` .
*Jacopo Beschi*
2021-04-26 12:49:15 -04:00
* Add option to disable joins for `has_one` associations.
In a multiple database application, associations can't join across
databases. When set, this option instructs Rails to generate 2 or
more queries rather than generating joins for `has_one` associations.
Set the option on a has one through association:
```ruby
class Person
belongs_to :dog
has_one :veterinarian, through: :dog, disable_joins: true
end
```
Then instead of generating join SQL, two queries are used for `@person.veterinarian` :
```
SELECT "dogs"."id" FROM "dogs" WHERE "dogs"."person_id" = ? [["person_id", 1]]
SELECT "veterinarians".* FROM "veterinarians" WHERE "veterinarians"."dog_id" = ? [["dog_id", 1]]
```
*Sarah Vessels* , *Eileen M. Uchitelle*
2021-05-02 16:20:07 -04:00
* `Arel::Visitors::Dot` now renders a complete set of properties when visiting
`Arel::Nodes::SelectCore` , `SelectStatement` , `InsertStatement` , `UpdateStatement` , and
`DeleteStatement` , which fixes #42026 . Previously, some properties were omitted.
*Mike Dalessio*
2021-05-02 15:29:17 -04:00
* `Arel::Visitors::Dot` now supports `Arel::Nodes::Bin` , `Case` , `CurrentRow` , `Distinct` ,
`DistinctOn` , `Else` , `Except` , `InfixOperation` , `Intersect` , `Lock` , `NotRegexp` , `Quoted` ,
`Regexp` , `UnaryOperation` , `Union` , `UnionAll` , `When` , and `With` . Previously, these node
types caused an exception to be raised by `Arel::Visitors::Dot#accept` .
*Mike Dalessio*
2021-04-25 20:08:50 -04:00
* Optimize `remove_columns` to use a single SQL statement.
```ruby
remove_columns :my_table, :col_one, :col_two
```
Now results in the following SQL:
```sql
ALTER TABLE "my_table" DROP COLUMN "col_one", DROP COLUMN "col_two"
```
*Jon Dufresne*
2021-04-20 04:41:00 -04:00
* Ensure `has_one` autosave association callbacks get called once.
Ensure has_one autosave association callbacks get called once
When saving a record, autosave adds callbacks to save its' associations.
Since the associations can have similar callbacks for the inverse,
endless loops could occur.
To prevent these endless loops, the callbacks for `has_many` and
`belongs_to` are defined as methods that only execute once.
This is implemented in the `define_non_cyclic_method` method.
However, this wasn't used for the `has_one` callbacks.
While `has_one` association callbacks didn't result in endless loops,
they could execute multiple times.
For example for a bidirectional `has_one` with autosave enabled,
the `save_has_one_association` gets called twice:
class Pirate < ActiveRecord::Base
has_one :ship, autosave: true
def save_has_one_association(reflection)
@count ||= 0
@count += 1 if reflection.name == :ship
super
end
end
class Ship < ActiveRecord::Base
belongs_to :pirate, autosave: true
end
pirate = Pirate.new(catchphrase: "Aye")
pirate.build_ship(name: "Nights Dirty Lightning")
pirate.save!
# this returns 2 instead of 1.
assert_equal 1, pirate.instance_variable_get(:@count)
This commit changes `has_one` autosave callbacks to be non-cyclic as
well. By doing this the autosave callback are made more consistent for
all 3 cases: `has_many`, `has_one` and `belongs_to`.
2021-04-14 15:16:35 -04:00
Change the `has_one` autosave callback to be non cyclic as well.
By doing this the autosave callback are made more consistent for
2021-04-20 04:41:00 -04:00
all 3 cases: `has_many` , `has_one` , and `belongs_to` .
Ensure has_one autosave association callbacks get called once
When saving a record, autosave adds callbacks to save its' associations.
Since the associations can have similar callbacks for the inverse,
endless loops could occur.
To prevent these endless loops, the callbacks for `has_many` and
`belongs_to` are defined as methods that only execute once.
This is implemented in the `define_non_cyclic_method` method.
However, this wasn't used for the `has_one` callbacks.
While `has_one` association callbacks didn't result in endless loops,
they could execute multiple times.
For example for a bidirectional `has_one` with autosave enabled,
the `save_has_one_association` gets called twice:
class Pirate < ActiveRecord::Base
has_one :ship, autosave: true
def save_has_one_association(reflection)
@count ||= 0
@count += 1 if reflection.name == :ship
super
end
end
class Ship < ActiveRecord::Base
belongs_to :pirate, autosave: true
end
pirate = Pirate.new(catchphrase: "Aye")
pirate.build_ship(name: "Nights Dirty Lightning")
pirate.save!
# this returns 2 instead of 1.
assert_equal 1, pirate.instance_variable_get(:@count)
This commit changes `has_one` autosave callbacks to be non-cyclic as
well. By doing this the autosave callback are made more consistent for
all 3 cases: `has_many`, `has_one` and `belongs_to`.
2021-04-14 15:16:35 -04:00
*Petrik de Heus*
Add option to skip joins for associations.
In a multiple database application, associations can't join across
databases. When set, this option tells Rails to make 2 or more queries
rather than using joins for associations.
Set the option on a has many through association:
```ruby
class Dog
has_many :treats, through: :humans, disable_joins: true
has_many :humans
end
```
Then instead of generating join SQL, two queries are used for `@dog.treats`:
```
SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ? [["dog_id", 1]]
SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?) [["human_id", 1], ["human_id", 2], ["human_id", 3]]
```
This code is extracted from a gem we use internally at GitHub which
means the implementation here is used in production daily and isn't
experimental.
I often get the question "why can't Rails do this automatically" so I
figured I'd include the answer in the commit. Rails can't do this
automatically because associations are lazily loaded. `dog.treats` needs
to load `Dog`, then `Human` and then `Treats`. When `dog.treats` is
called Rails pre-generates the SQL that will be run and puts that
information into a reflection object. Because the SQL parts are pre-generated,
as soon as `dog.treats` is loaded it's too late to skip a join. The join
is already available on the object and that join is what's run to load
`treats` from `dog` through `humans`. I think the only way to avoid setting
an option on the association is to rewrite how and when the SQL is
generated for associations which is a large undertaking. Basically the
way that Active Record associations are designed, it is currently
impossible to have Rails figure out to not join (loading the association
will cause the join to occur, and that join will raise an error if the
models don't live in the same db).
The original implementation was written by me and Aaron. Lee helped port
over tests, and I refactored the extraction to better match Rails style.
Co-authored-by: Lee Quarella <leequarella@gmail.com>
Co-authored-by: Aaron Patterson <aaron@rubyonrails.org>
2020-11-03 13:01:41 -05:00
* Add option to disable joins for associations.
In a multiple database application, associations can't join across
databases. When set, this option instructs Rails to generate 2 or
more queries rather than generating joins for associations.
Set the option on a has many through association:
```ruby
class Dog
has_many :treats, through: :humans, disable_joins: true
has_many :humans
end
```
Then instead of generating join SQL, two queries are used for `@dog.treats` :
```
SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ? [["dog_id", 1]]
SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?) [["human_id", 1], ["human_id", 2], ["human_id", 3]]
```
*Eileen M. Uchitelle* , *Aaron Patterson* , *Lee Quarella*
2021-03-21 18:17:22 -04:00
* Add setting for enumerating column names in SELECT statements.
2021-04-25 07:09:39 -04:00
Adding a column to a PostgreSQL database, for example, while the application is running can
2021-03-21 18:17:22 -04:00
change the result of wildcard `SELECT *` queries, which invalidates the result
2021-04-15 19:34:30 -04:00
of cached prepared statements and raises a `PreparedStatementCacheExpired` error.
2021-03-21 18:17:22 -04:00
2021-04-15 19:34:30 -04:00
When enabled, Active Record will avoid wildcards and always include column names
2021-03-21 18:17:22 -04:00
in `SELECT` queries, which will return consistent results and avoid prepared
statement errors.
Before:
```ruby
Book.limit(5)
# SELECT * FROM books LIMIT 5
```
After:
```ruby
# config/application.rb
module MyApp
class Application < Rails::Application
config.active_record.enumerate_columns_in_select_statements = true
end
end
# or, configure per-model
class Book < ApplicationRecord
self.enumerate_columns_in_select_statements = true
end
```
```ruby
Book.limit(5)
# SELECT id, author_id, name, format, status, language, etc FROM books LIMIT 5
```
*Matt Duszynski*
2021-04-12 13:23:46 -04:00
* Allow passing SQL as `on_duplicate` value to `#upsert_all` to make it possible to use raw SQL to update columns on conflict:
2021-04-12 11:01:42 -04:00
```ruby
Book.upsert_all(
[{ id: 1, status: 1 }, { id: 2, status: 1 }],
2021-04-12 13:23:46 -04:00
on_duplicate: Arel.sql("status = GREATEST(books.status, EXCLUDED.status)")
2021-04-12 11:01:42 -04:00
)
```
*Vladimir Dementyev*
2021-04-12 13:23:46 -04:00
* Allow passing SQL as `returning` statement to `#upsert_all` :
2019-03-15 11:18:45 -04:00
```ruby
Article.insert_all(
2021-07-20 21:08:08 -04:00
[
2021-04-12 13:23:46 -04:00
{ title: "Article 1", slug: "article-1", published: false },
{ title: "Article 2", slug: "article-2", published: false }
2019-03-15 11:18:45 -04:00
],
2021-04-12 13:23:46 -04:00
returning: Arel.sql("id, (xmax = '0') as inserted, name as new_name")
2019-03-15 11:18:45 -04:00
)
```
*Vladimir Dementyev*
2021-04-02 13:51:47 -04:00
* Deprecate `legacy_connection_handling` .
*Eileen M. Uchitelle*
2021-04-02 07:40:00 -04:00
* Add attribute encryption support.
Encrypted attributes are declared at the model level. These
are regular Active Record attributes backed by a column with
the same name. The system will transparently encrypt these
attributes before saving them into the database and will
decrypt them when retrieving their values.
2021-04-11 11:44:46 -04:00
2021-04-02 07:40:00 -04:00
```ruby
class Person < ApplicationRecord
encrypts :name
encrypts :email_address, deterministic: true
end
```
You can learn more in the [Active Record Encryption
guide](https://edgeguides.rubyonrails.org/active_record_encryption.html).
*Jorge Manrubia*
2021-03-28 03:15:50 -04:00
* Changed Arel predications `contains` and `overlaps` to use
`quoted_node` so that PostgreSQL arrays are quoted properly.
*Bradley Priest*
2021-07-20 21:08:08 -04:00
* Add mode argument to record level `strict_loading!` .
2021-03-03 16:33:32 -05:00
This argument can be used when enabling strict loading for a single record
to specify that we only want to raise on n plus one queries.
```ruby
developer.strict_loading!(mode: :n_plus_one_only)
developer.projects.to_a # Does not raise
developer.projects.first.client # Raises StrictLoadingViolationError
```
Previously, enabling strict loading would cause any lazily loaded
association to raise an error. Using `n_plus_one_only` mode allows us to
lazily load belongs_to, has_many, and other associations that are fetched
through a single query.
*Dinah Shi*
2021-07-20 21:08:08 -04:00
* Fix Float::INFINITY assignment to datetime column with postgresql adapter.
2021-03-21 12:12:22 -04:00
Before:
```ruby
# With this config
ActiveRecord::Base.time_zone_aware_attributes = true
# and the following schema:
create_table "postgresql_infinities" do |t|
t.datetime "datetime"
end
# This test fails
record = PostgresqlInfinity.create!(datetime: Float::INFINITY)
assert_equal Float::INFINITY, record.datetime # record.datetime gets nil
```
After this commit, `record.datetime` gets `Float::INFINITY` as expected.
*Shunichi Ikegami*
2021-03-03 03:45:39 -05:00
* Type cast enum values by the original attribute type.
The notable thing about this change is that unknown labels will no longer match 0 on MySQL.
```ruby
class Book < ActiveRecord::Base
enum :status, { proposed: 0, written: 1, published: 2 }
end
```
Before:
```ruby
# SELECT `books` .* FROM `books` WHERE `books` .`status` = 'prohibited' LIMIT 1
Book.find_by(status: :prohibited)
# => #< Book id: 1 , status: " proposed " , . . . > (for mysql2 adapter)
# => ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "prohibited" (for postgresql adapter)
# => nil (for sqlite3 adapter)
```
After:
```ruby
# SELECT `books` .* FROM `books` WHERE `books` .`status` IS NULL LIMIT 1
Book.find_by(status: :prohibited)
# => nil (for all adapters)
```
*Ryuta Kamizono*
2021-07-20 21:08:08 -04:00
* Fixtures for `has_many :through` associations now load timestamps on join tables.
2021-02-23 12:58:25 -05:00
Given this fixture:
```yml
### monkeys.yml
george:
name: George the Monkey
fruits: apple
### fruits.yml
apple:
name: apple
```
If the join table (`fruit_monkeys`) contains `created_at` or `updated_at` columns,
these will now be populated when loading the fixture. Previously, fixture loading
would crash if these columns were required, and leave them as null otherwise.
*Alex Ghiculescu*
2021-07-20 21:08:08 -04:00
* Allow applications to configure the thread pool for async queries.
2021-02-18 13:10:57 -05:00
Some applications may want one thread pool per database whereas others want to use
2021-04-11 12:57:29 -04:00
a single global thread pool for all queries. By default, Rails will set `async_query_executor`
2021-02-23 13:53:07 -05:00
to `nil` which will not initialize any executor. If `load_async` is called and no executor
has been configured, the query will be executed in the foreground.
2021-02-18 13:10:57 -05:00
To create one thread pool for all database connections to use applications can set
`config.active_record.async_query_executor` to `:global_thread_pool` and optionally define
`config.active_record.global_executor_concurrency` . This defaults to 4. For applications that want
to have a thread pool for each database connection, `config.active_record.async_query_executor` can
be set to `:multi_thread_pool` . The configuration for each thread pool is set in the database
configuration.
*Eileen M. Uchitelle*
Allow new syntax for `enum` to avoid leading `_` from reserved options
Unlike other features built on Attribute API, reserved options for
`enum` has leading `_`.
* `_prefix`/`_suffix`: #19813, #20999
* `_scopes`: #34605
* `_default`: #39820
That is due to `enum` takes one hash argument only, which contains both
enum definitions and reserved options.
I propose new syntax for `enum` to avoid leading `_` from reserved
options, by allowing `enum(attr_name, ..., **options)` more Attribute
API like syntax.
Before:
```ruby
class Book < ActiveRecord::Base
enum status: [ :proposed, :written ], _prefix: true, _scopes: false
enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
end
```
After:
```ruby
class Book < ActiveRecord::Base
enum :status, [ :proposed, :written ], prefix: true, scopes: false
enum :cover, [ :hard, :soft ], suffix: true, default: :hard
end
```
2021-02-04 00:13:16 -05:00
* Allow new syntax for `enum` to avoid leading `_` from reserved options.
Before:
```ruby
class Book < ActiveRecord::Base
enum status: [ :proposed, :written ], _prefix: true, _scopes: false
enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
end
```
After:
```ruby
class Book < ActiveRecord::Base
enum :status, [ :proposed, :written ], prefix: true, scopes: false
enum :cover, [ :hard, :soft ], suffix: true, default: :hard
end
```
*Ryuta Kamizono*
2021-02-08 08:22:26 -05:00
* Add `ActiveRecord::Relation#load_async` .
This method schedules the query to be performed asynchronously from a thread pool.
If the result is accessed before a background thread had the opportunity to perform
the query, it will be performed in the foreground.
This is useful for queries that can be performed long enough before their result will be
2021-02-25 14:27:29 -05:00
needed, or for controllers which need to perform several independent queries.
2021-02-08 08:22:26 -05:00
```ruby
def index
@categories = Category.some_complex_scope.load_async
@posts = Post.some_complex_scope.load_async
end
```
2021-06-26 19:01:14 -04:00
Active Record logs will also include timing info for the duration of how long
the main thread had to wait to access the result. This timing is useful to know
whether or not it's worth to load the query asynchronously.
```
DEBUG -- : Category Load (62.1ms) SELECT * FROM `categories` LIMIT 50
DEBUG -- : ASYNC Post Load (64ms) (db time 126.1ms) SELECT * FROM `posts` LIMIT 100
```
The duration in the first set of parens is how long the main thread was blocked
waiting for the results, and the second set of parens with "db time" is how long
the entire query took to execute.
2021-02-08 08:22:26 -05:00
*Jean Boussier*
2021-02-14 03:41:49 -05:00
* Implemented `ActiveRecord::Relation#excluding` method.
This method excludes the specified record (or collection of records) from
the resulting relation:
```ruby
Post.excluding(post)
Post.excluding(post_one, post_two)
```
Also works on associations:
```ruby
post.comments.excluding(comment)
post.comments.excluding(comment_one, comment_two)
```
This is short-hand for `Post.where.not(id: post.id)` (for a single record)
and `Post.where.not(id: [post_one.id, post_two.id])` (for a collection).
*Glen Crawford*
2021-02-11 17:32:20 -05:00
* Skip optimised #exist ? query when #include ? is called on a relation
2021-07-20 21:08:08 -04:00
with a having clause.
2021-02-11 17:32:20 -05:00
Relations that have aliased select values AND a having clause that
references an aliased select value would generate an error when
#include ? was called, due to an optimisation that would generate
call #exists ? on the relation instead, which effectively alters
the select values of the query (and thus removes the aliased select
values), but leaves the having clause intact. Because the having
clause is then referencing an aliased column that is no longer
present in the simplified query, an ActiveRecord::InvalidStatement
error was raised.
2021-04-11 12:57:29 -04:00
A sample query affected by this problem:
2021-02-11 17:32:20 -05:00
```ruby
Author.select('COUNT(*) as total_posts', 'authors.*')
.joins(:posts)
.group(:id)
.having('total_posts > 2')
.include?(Author.first)
```
This change adds an addition check to the condition that skips the
simplified #exists ? query, which simply checks for the presence of
a having clause.
2021-07-20 21:08:08 -04:00
Fixes #41417 .
2021-02-11 17:32:20 -05:00
*Michael Smart*
2021-02-11 18:51:53 -05:00
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
2021-02-25 14:27:29 -05:00
without Rails knowledge (e.g., if app gets killed during long-running query or due to Rack::Timeout), app won't end
2021-07-20 21:08:08 -04:00
up in perpetual crash state for being inconsistent with PostgreSQL.
2021-01-06 11:34:37 -05:00
*wbharding* , *Martin Tepper*
2021-02-10 14:26:40 -05:00
* Add ability to apply `scoping` to `all_queries` .
Some applications may want to use the `scoping` method but previously it only
worked on certain types of queries. This change allows the `scoping` method to apply
to all queries for a model in a block.
```ruby
Post.where(blog_id: post.blog_id).scoping(all_queries: true) do
post.update(title: "a post title") # adds `posts.blog_id = 1` to the query
end
```
*Eileen M. Uchitelle*
2021-02-11 15:09:04 -05:00
* `ActiveRecord::Calculations.calculate` called with `:average`
2021-06-14 18:29:05 -04:00
(aliased as `ActiveRecord::Calculations.average` ) will now use column-based
2021-04-11 12:57:29 -04:00
type casting. This means that floating-point number columns will now be
2021-02-11 15:09:04 -05:00
aggregated as `Float` and decimal columns will be aggregated as `BigDecimal` .
2021-02-10 16:37:18 -05:00
2021-02-11 15:09:04 -05:00
Integers are handled as a special case returning `BigDecimal` always
(this was the case before already).
2021-02-10 16:37:18 -05:00
```ruby
# With the following schema:
create_table "measurements" do |t|
t.float "temperature"
end
# Before:
Measurement.average(:temperature).class
# => BigDecimal
# After:
Measurement.average(:temperature).class
# => Float
```
2021-02-11 15:09:04 -05:00
Before this change, Rails just called `to_d` on average aggregates from the
database adapter. This is not the case anymore. If you relied on that kind
of magic, you now need to register your own `ActiveRecord::Type`
(see `ActiveRecord::Attributes::ClassMethods` for documentation).
2021-02-10 16:37:18 -05:00
*Josua Schmid*
2021-07-20 21:08:08 -04:00
* PostgreSQL: introduce `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type` .
2021-03-09 14:29:07 -05:00
This setting controls what native type Active Record should use when you call `datetime` in
a migration or schema. It takes a symbol which must correspond to one of the configured
`NATIVE_DATABASE_TYPES` . The default is `:timestamp` , meaning `t.datetime` in a migration
will create a "timestamp without time zone" column. To use "timestamp with time zone",
change this to `:timestamptz` in an initializer.
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
*Alex Ghiculescu*
2021-02-10 12:59:31 -05:00
* PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb` .
Previously they dumped as `t.datetime :column_name` , now they dump as `t.timestamptz :column_name` ,
and are created as `timestamptz` columns when the schema is loaded.
*Alex Ghiculescu*
2021-02-04 16:32:25 -05:00
* Removing trailing whitespace when matching columns in
`ActiveRecord::Sanitization.disallow_raw_sql!` .
*Gannon McGibbon* , *Adrian Hirt*
2021-07-20 21:08:08 -04:00
* Expose a way for applications to set a `primary_abstract_class` .
2021-01-25 10:52:56 -05:00
Multiple database applications that use a primary abstract class that is not
named `ApplicationRecord` can now set a specific class to be the `primary_abstract_class` .
```ruby
class PrimaryApplicationRecord
self.primary_abstract_class
end
```
When an application boots it automatically connects to the primary or first database in the
database configuration file. In a multiple database application that then call `connects_to`
needs to know that the default connection is the same as the `ApplicationRecord` connection.
2021-04-11 12:57:29 -04:00
However, some applications have a differently named `ApplicationRecord` . This prevents Active
2021-01-25 10:52:56 -05:00
Record from opening duplicate connections to the same database.
*Eileen M. Uchitelle* , *John Crepezzi*
2021-01-21 21:32:55 -05:00
* Support hash config for `structure_dump_flags` and `structure_load_flags` flags
Now that Active Record supports multiple databases configuration
we need a way to pass specific flags for dump/load databases since
the options are not the same for different adapters.
We can use in the original way:
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
2021-07-20 21:08:08 -04:00
# or
2021-01-21 21:32:55 -05:00
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
```
2021-01-23 05:59:39 -05:00
2021-01-21 21:32:55 -05:00
And also use it passing a hash, with one or more keys, where the key
is the adapter
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
mysql2: ['--no-defaults', '--skip-add-drop-table'],
postgres: '--no-tablespaces'
2021-01-23 05:59:39 -05:00
}
2021-01-21 21:32:55 -05:00
```
*Gustavo Gonzalez*
2021-01-16 12:06:25 -05:00
* Connection specification now passes the "url" key as a configuration for the
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
are assumed to be adapter specification urls.
Fixes #41137 .
*Jonathan Bracy*
2021-01-19 16:12:18 -05:00
* Allow to opt-out of `strict_loading` mode on a per-record base.
This is useful when strict loading is enabled application wide or on a
model level.
```ruby
class User < ApplicationRecord
2021-02-04 07:36:09 -05:00
has_many :bookmarks
2021-01-19 16:12:18 -05:00
has_many :articles, strict_loading: true
end
user = User.first
2021-01-23 05:59:39 -05:00
user.articles # => ActiveRecord::StrictLoadingViolationError
user.bookmarks # => #< ActiveRecord::Associations::CollectionProxy >
2021-01-19 16:12:18 -05:00
2021-01-23 05:59:39 -05:00
user.strict_loading!(true) # => true
user.bookmarks # => ActiveRecord::StrictLoadingViolationError
user.strict_loading!(false) # => false
user.bookmarks # => #< ActiveRecord::Associations::CollectionProxy >
user.articles.strict_loading!(false) # => #< ActiveRecord::Associations::CollectionProxy >
2021-01-19 16:12:18 -05:00
```
*Ayrton De Craene*
2020-11-23 18:32:11 -05:00
* Add `FinderMethods#sole` and `#find_sole_by` to find and assert the
presence of exactly one record.
Used when you need a single row, but also want to assert that there aren't
multiple rows matching the condition; especially for when database
constraints aren't enough or are impractical.
```ruby
Product.where(["price = %?", price]).sole
# => ActiveRecord::RecordNotFound (if no Product with given price)
# => #< Product . . . > (if one Product with given price)
# => ActiveRecord::SoleRecordExceeded (if more than one Product with given price)
2020-12-30 19:02:34 -05:00
user.api_keys.find_sole_by(key: key)
2020-11-23 18:32:11 -05:00
# as above
```
*Asherah Connor*
2020-12-29 07:11:16 -05:00
* Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
2020-12-10 10:37:22 -05:00
Before:
```ruby
2020-12-30 00:44:02 -05:00
class User
def admin
false # Overriding the getter to always return false
2020-12-10 10:37:22 -05:00
end
2020-12-30 00:44:02 -05:00
end
2020-12-10 10:37:22 -05:00
2020-12-30 00:44:02 -05:00
user = User.first
user.update(admin: true)
2020-12-10 10:37:22 -05:00
2020-12-30 00:44:02 -05:00
user.admin # false (as expected, due to the getter overwrite)
user.admin? # true (not expected, returned the DB column value)
2020-12-10 10:37:22 -05:00
```
After this commit, `user.admin?` above returns false, as expected.
2020-12-30 00:44:02 -05:00
Fixes #40771 .
*Felipe*
2020-12-18 01:06:16 -05:00
* Allow delegated_type to be specified primary_key and foreign_key.
Since delegated_type assumes that the foreign_key ends with `_id` ,
`singular_id` defined by it does not work when the foreign_key does
not end with `id` . This change fixes it by taking into account
`primary_key` and `foreign_key` in the options.
*Ryota Egusa*
2020-09-17 16:12:58 -04:00
* Expose an `invert_where` method that will invert all scope conditions.
```ruby
class User
scope :active, -> { where(accepted: true, locked: false) }
end
User.active
# ... WHERE `accepted` = 1 AND `locked` = 0
User.active.invert_where
# ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
```
*Kevin Deisz*
allow passing false to :polymorphic option of belongs_to
before this, passing false would raise the following error
because a condition in AR would disregard the option entirely
if false was passed.
ArgumentError: Unknown key: :polymorphic. Valid keys are:
:class_name, :anonymous_class, :primary_key, :foreign_key,
:dependent, :validate, :inverse_of, :strict_loading, :autosave,
:required, :touch, :counter_cache, :optional, :default
2020-12-17 22:38:36 -05:00
* Restore possibility of passing `false` to :polymorphic option of `belongs_to` .
Previously, passing `false` would trigger the option validation logic
to throw an error saying :polymorphic would not be a valid option.
*glaszig*
2020-12-17 14:41:00 -05:00
* Remove deprecated `database` kwarg from `connected_to` .
*Eileen M. Uchitelle* , *John Crepezzi*
2020-12-11 10:52:00 -05:00
* Allow adding nonnamed expression indexes to be revertible.
Previously, the following code would raise an error, when executed while rolling back,
and the index name should be specified explicitly. Now, the index name is inferred
automatically.
2021-07-20 21:08:08 -04:00
2020-12-11 10:52:00 -05:00
```ruby
add_index(:items, "to_tsvector('english', description)")
```
2021-07-20 21:08:08 -04:00
Fixes #40732 .
2020-12-11 10:52:00 -05:00
*fatkodima*
2020-11-24 12:38:49 -05:00
* Only warn about negative enums if a positive form that would cause conflicts exists.
Fixes #39065 .
*Alex Ghiculescu*
2020-11-19 17:20:45 -05:00
* Add option to run `default_scope` on all queries.
2021-04-11 13:30:55 -04:00
Previously, a `default_scope` would only run on select or insert queries. In some cases, like non-Rails tenant sharding solutions, it may be desirable to run `default_scope` on all queries in order to ensure queries are including a foreign key for the shard (i.e. `blog_id` ).
2020-11-19 17:20:45 -05:00
Now applications can add an option to run on all queries including select, insert, delete, and update by adding an `all_queries` option to the default scope definition.
```ruby
class Article < ApplicationRecord
default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
end
```
*Eileen M. Uchitelle*
2020-11-26 08:15:18 -05:00
* Add `where.associated` to check for the presence of an association.
```ruby
# Before:
account.users.joins(:contact).where.not(contact_id: nil)
# After:
account.users.where.associated(:contact)
```
Also mirrors `where.missing` .
*Kasper Timm Hansen*
2020-08-07 15:36:22 -04:00
* Allow constructors (`build_association` and `create_association` ) on
`has_one :through` associations.
*Santiago Perez Perret*
2020-04-14 10:33:56 -04:00
2020-12-02 18:37:26 -05:00
Please check [6-1-stable ](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md ) for previous changes.