$ the-wire · showcase
Rails cuts redundant joins in through associations
By RepoJournal · Filed · About Rails
A new Rails commit avoids duplicate table joins in scoped `has_many :through` associations, cutting redundant SQL.
Rails now drops a redundant join from a scoped `has_many :through` association when the through chain already covers a `belongs_to` or `has_one` reflection, leaving collection joins intact because removing one changes the returned row count [1]. This addresses issue #51259 and results in leaner queries for common through scopes. Also, `ActiveRecord::Coders::JSON` no longer raises `NameError` when given encode options [2]. Encrypted fixtures for `json`/`jsonb` columns no longer serialize the payload twice, fixing `ActiveRecord::Encryption::Errors::Decryption` on read [3]. ActionView::Base now makes some settings shareable to Ractors, preparing for Ruby 4.0 support [4].
Action items
- → Review through-association scopes that join covered reflections for query changes rails/rails [plan]
- → Test encrypted JSON fixtures after the serialization fix rails/rails [monitor]
References
- [1] Avoid a redundant join in scoped through associations ↗ rails/rails
- [2] Merge pull request #58612 from lazerg/fix-json-coder-encode-options ↗ rails/rails
- [3] Fix encrypted fixtures for JSON columns ↗ rails/rails
- [4] Make some ActionView::Base settings shareable ↗ rails/rails