Rails: The Sharp Parts. A Polymorphic Type Is Not a Foreign Key | baweaver

03-Jul-2026 12
Polymorphic associations store a relationship as a class name in a string with no foreign key. That has unintended consequences which may not be obvious, and this article covers five of them.Last time we made a T::Struct the only thing allowed to cross a pack boundary: typed, inert, and reviewable in five seconds. This article is about polymorphic associations, and sharp edges I’ve had to contend with, especially around delegators when trying a strangler fig refactoring pattern. I still have an open Rails issue on the delegator bug I need to find a way to land. To not bury the lede, at scale my personal answer to polymorphic associations? Don’t.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle