Performance: Why associations connect models
MEDIUM IMPACT
Associations affect how Rails loads related data, impacting page load speed and memory usage.
posts = Post.includes(:user).all posts.each do |post| puts post.user.name end
posts = Post.all posts.each do |post| puts post.user.name end
| Pattern | Database Queries | Memory Usage | Load Time Impact | Verdict |
|---|---|---|---|---|
| Lazy loading associations | N+1 queries | Higher due to repeated queries | Slower with more records | [X] Bad |
| Eager loading associations | 2 queries | Lower by batching data | Faster and consistent | [OK] Good |