This Week in Rails

March 24, 2023

Composite primary keys improvements and more

Hi, it’s Wojtek with this week’s changes in the Rails codebase.

Allow specifying WHERE clauses with column-tuple syntax.
Querying through Active Record where now accepts a tuple syntax which accepts, as a key, an array of columns and, as a value, an array of corresponding tuples. This improves support for composite primary keys.

Accept composite primary key in id=
This feature modifies the Active Record id accessor to accept an array in composite primary key contexts.

Extract sample rate in the Audio Analyzer
Add sample_rate to ActiveStorage::Analyzer::AudioAnalyzer output.

Run a load hook when TestFixtures is included
Introduces active_record_fixtures lazy load hook. Hooks defined with this name will be run whenever TestFixtures is included in a class.

ActiveSupport.on_load(:active_record_fixtures) do
  self.fixture_paths << "test/fixtures"
end

Allow SQL Warnings to be ignored using error codes

Active Record configuration allows now to ignore the warning codes like this:

config.active_record.db_warnings_ignore = [
  "1062" # MySQL Error 1062: Duplicate entry
]

You can view the whole list of changes
here.
We had 21 contributors to the Rails codebase this past week!

Until next time!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.