What is polymorphic association in Rails?
Updated May 24, 2026
Short answer
Polymorphic associations allow a model to belong to multiple other models.
Deep explanation
A single association can reference different models using type and id fields.
Real-world example
Comments on posts, photos, and videos using one table.
Common mistakes
- Overusing polymorphism when simple associations suffice.
Follow-up questions
- What columns are needed?
- When to avoid polymorphism?