Performance: Associations (hasMany, belongsTo)
MEDIUM IMPACT
This affects how many database queries and data processing happen during page load and user interactions.
const posts = await Post.findAll({ include: [{ model: User, as: 'author' }] }); res.json(posts);
const posts = await Post.findAll(); for (const post of posts) { post.author = await User.findByPk(post.userId); } res.json(posts);
| Pattern | Database Queries | Response Time | Server Load | Verdict |
|---|---|---|---|---|
| Lazy loading associations (N+1 queries) | N+1 queries | High | High | [X] Bad |
| Eager loading associations (single query) | 1 query | Low | Low | [OK] Good |