The Wire · Showcase
Rails fixes composite foreign key tracking across counter cache and autosave
By RepoJournal · Filed · About Rails
Belongs_to associations with aliased or composite foreign keys were silently failing change detection, breaking counter cache increments, touch callbacks, and validation.
Rails shipped fixes across three related change tracking failures this cycle. The first resolves attribute aliases in belongs_to change tracking [1], where querying a foreign key by its alias never reported changes, causing counter_cache to go negative on destroy and touch: true to skip the previous parent [2]. That fix is now cached at initialization time for reuse across validation and touch sites [3]. The second addresses composite foreign keys in counter cache and autosave [4], where the Array form of reflection.foreign_key was coerced via to_s, making dirty tracking no-op. The third attack the same surface area with slightly different scope [5]. Propshaft also landed a test infrastructure fix [6] extracting duplicate assertions to a shared concern and making Resolver lazy-loaded so JSON.parse stubs take effect. Over at action_push_native, the gem now surfaces FCM quota violation details on throttle errors [7], allowing apps to distinguish between device message rate, topic message rate, and project-wide quota limits, which were previously all collapsed to QUOTA_EXCEEDED. Dependency bumps brought ActiveRecord and ActiveJob to 8.1.3.1 [8], [9], webmock to 3.26.2 [10], and actions/checkout to v7 [11].
One email a day. Unsubscribe in one click.
Keep up with Rails in about 3 minutes a day: what actually shipped — the commits, pull requests, releases, and security advisories that matter.
One email a day. Unsubscribe in one click. Read a past issue →
Action items
- → Review belongs_to associations using alias_attribute on foreign keys - they now track changes correctly rails/rails [plan]
- → Update action_push_native to 0.x (check current version) to handle FCM quota violations if you differentiate throttle reasons rails/action_push_native [monitor]
- → Bump ActiveRecord and ActiveJob to 8.1.3.1 on next dependency refresh rails/rails [plan]
References
- [1] Resolve attribute aliases in belongs_to change tracking ↗ rails/rails
- [2] Merge pull request #58354 from 55728/fix-belongs-to-aliased-foreign-key-tracking rails/rails
- [3] Cache alias-resolved foreign key/type on BelongsToAssociation rails/rails
- [4] Honor composite / aliased FKs in belongs_to counter cache, autosave, and has_many :through nullify ↗ rails/rails
- [5] Honor composite FKs in belongs_to counter cache, autosave, and has_many :through nullify rails/rails
- [6] Fix assertionless tests in Resolver::StaticTest ↗ rails/propshaft
- [7] Surface FCM quota violations on throttle errors ↗ rails/action_push_native
- [8] Bump activerecord from 8.1.2 to 8.1.3.1 ↗ rails/action_push_native
- [9] Bump activejob from 8.1.2 to 8.1.3.1 ↗ rails/action_push_native
- [10] Bump webmock from 3.26.1 to 3.26.2 ↗ rails/action_push_native
- [11] Bump actions/checkout from 4 to 7 ↗ rails/action_push_native