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.
Rails: The Sharp Parts. A Polymorphic Type Is Not a Foreign Key | baweaver #ruby #rubydeveloper #rubyonrails #Rails: #Sharp #Parts. #Polymorphic #Foreign #baweaver #type https://www.rubyonrails.ba/link/rails-the-sharp-parts-a-polymorphic-type-is-not-a-foreign-key-baweaver