Three ActiveRecord Mistakes

Three ActiveRecord Mistakes

1/10/2025

notes

i still question the tradeoffs being made by the complete adoption of an ORM. i don't think it's a simple decision and when you've made one, you will take on the brunt of the tradeoffs.

i have experiences with well designed query builders that have shown me there is a path to the benefits of an ORM without the opaque costs of one.

with that said, either approach you take, it's good to know about the tradeoffs and prepare yourself. the n+1 problem is real and way to easy given the api and too many aliases used by rails...

link

https://www.speedshop.co/2019/01/10/three-activerecord-mistakes.html

summary

Many Rails developers don't understand what causes ActiveRecord to actually execute a SQL query. Let's look at three common cases: misuse of the count method, using where to select subsets, and the present? predicate. You may be causing extra queries and N+1s through the abuse of these three methods.

tags

activerecord ꞏ rails ꞏ mistakes ꞏ ruby on rails ꞏ n-plus-one ꞏ count ꞏ where ꞏ present