Friday, March 24, 2023

Composite primary keys improvements and more

Posted by Wojtek

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"

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!

Subscribe to get these updates mailed to you.