Complete the code to eager load the associated posts for users.
User.[1](:posts)The includes method loads associated records to avoid N+1 queries.
Complete the code to join users with their posts in a query.
User.[1](:posts).where(posts: { published: true })The joins method creates an INNER JOIN in SQL to filter records based on associated tables.
Fix the error in the code to eager load comments for posts.
Post.[1](:comments).where('comments.approved = ?', true)
Using joins allows filtering on associated tables in the WHERE clause; includes alone may not work with conditions on the joined table.
Fill both blanks to join authors and eager load their books.
Author.[1](:books).[2](:books)
First joins creates the SQL join, then includes eager loads the books to avoid extra queries.
Fill all three blanks to create a hash of book titles and their authors' names for published books.
Book.[1](:author).where(published: true).pluck('books.title', 'authors.name').to_h.transform_keys { |k| k.[2] }.transform_values { |v| v.[3] }
authors.name won't be available without a join.joins creates the SQL join necessary to select authors.name alongside books.title in the pluck query, upcase makes titles uppercase, and downcase makes author names lowercase.
