ORMs are criticized for the wrong reasons
Blog post from Lago
Object-Relational Mappings (ORMs) are often criticized for being inefficient and breaking software design principles like the Single Responsibility Principle (SRP) and Separation of Concerns (SOC), yet these criticisms are considered exaggerated by the author. ORMs are not inherently bad; they are simply abstractions that can lead to performance hits and decreased visibility if misused. The primary issues with ORMs include the N+1 query problem, where multiple roundtrips to the database occur, and challenges with visibility and error translation, especially when unexpected results require inspection of the SQL queries generated. Despite these drawbacks, ORMs can be nearly as efficient as raw SQL when used correctly and offer features that can mitigate common issues like N+1 scenarios. The author's experience with Active Record prompted a reevaluation of ORM usage, noting that developers often rely too heavily on host language logic instead of utilizing ORM features to optimize queries, and suggesting that executing raw SQL queries within an ORM can sometimes be beneficial for debugging or improving performance.