Rails Daily: Composite Foreign Key Validation Fix
Felix-d fixed a validation condition bug for belongs_to associations with composite foreign keys in ActiveRecord. The fix ensures proper validation behavior when belongs_to_required_validates_foreign_key is disabled.
Duration: PT1M52S
Episode overview
This episode is a short developer briefing from Rails Daily.
It explains recent repository work in plain language.
- Show: Rails Daily
- Published: 2026-04-04T10:01:34Z
- Audio duration: PT1M52S
Transcript excerpt
This excerpt keeps the crawler page concise. Listen to the episode or use the RSS feed for the full update.
Good morning, this is Rails Daily for April 4th, 2026.
Felix-d merged a fix for belongs_to validation condition handling with composite foreign keys. The issue occurred when `belongs_to_required_validates_foreign_key` is set to false, which has been the default since Rails 7.1. In this configuration, Rails uses a conditional presence validator that checks if foreign…
The problem was that the existing validation condition only worked with single foreign keys. For composite foreign keys - where an association uses multiple columns - the condition would fail because it expected a single value rather than an array of values. This could lead to validation running incorrectly or not…
The fix updates the condition lambda in the belongs_to association builder to properly handle both single and composite foreign key scenarios. The change adds logic to check if the foreign key is an array and validates each component appropriately. Felix-d included comprehensive tests covering the composite foreign…
The pull request received one approval and minimal discussion, indicating this was a straightforward bug fix. The changes touch three files with 39 additions and 2 deletions, keeping the…
What's…
Nearby episodes from Rails Daily
- Weekly Recap - Developer Experience & Security Enhancements
- HTTP Request Safety Methods Added
- Weekly Recap - Composite Keys & Performance Optimizations
- Weekly Recap - Composite Keys & Performance Optimizations
- Documentation and Ruby 3.2 Cleanup
- ActiveSupport Performance and Flexibility Updates
- Composite Keys and AI Agent Integration
- Performance and Developer Experience Improvements