Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to eager load the associated posts for users.
Ruby on Rails
users = User.[1](:posts) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'joins' instead of 'includes' causes N+1 queries.
Using 'select' does not load associations.
✗ Incorrect
Using includes loads the associated posts in one query to prevent N+1 queries.
2fill in blank
mediumComplete the code to eager load comments for posts.
Ruby on Rails
posts = Post.[1](:comments) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'where' filters records but does not eager load.
Using 'order' or 'group' does not load associations.
✗ Incorrect
includes loads the comments with posts to prevent multiple queries.
3fill in blank
hardFix the error in the code to eager load authors for articles.
Ruby on Rails
articles = Article.[1](:author) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' or 'find' does not eager load associations.
Using 'pluck' only selects columns, no associations.
✗ Incorrect
includes is the correct method to eager load the author association.
4fill in blank
hardFill both blanks to eager load comments and their authors for posts.
Ruby on Rails
posts = Post.[1]([2]: :author)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'joins' instead of 'includes' causes N+1 queries.
Using 'where' does not eager load associations.
✗ Incorrect
Use includes with nested association comments: :author to eager load both.
5fill in blank
hardFill all three blanks to eager load categories, tags, and their creators for articles.
Ruby on Rails
articles = Article.[1]([2], [3]: :creator)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'joins' instead of 'includes' causes multiple queries.
Not nesting the creator association under tags.
✗ Incorrect
Use includes with :categories and nested :tags => :creator to eager load all associations.