Bird
0
0

Given this Remix loader code using Prisma:

medium📝 component behavior Q13 of 15
Remix - Performance
Given this Remix loader code using Prisma:
const posts = await prisma.post.findMany({ where: { published: true }, orderBy: { createdAt: 'desc' }, take: 5 });

What will be the result?
AThrows a syntax error due to orderBy usage
BReturns all posts regardless of published status
CReturns 5 oldest posts including unpublished
DReturns the 5 most recent published posts
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the filter condition

    The 'where' clause filters posts to only those with 'published: true'.
  2. Step 2: Understand sorting and limiting

    'orderBy: { createdAt: "desc" }' sorts posts newest first, and 'take: 5' limits to 5 posts.
  3. Final Answer:

    Returns the 5 most recent published posts -> Option D
  4. Quick Check:

    Filter + sort + limit = 5 newest published posts [OK]
Quick Trick: Filter first, then sort descending, then limit [OK]
Common Mistakes:
MISTAKES
  • Ignoring the 'where' filter and returning all posts
  • Thinking 'orderBy' sorts ascending by default
  • Assuming syntax error with 'orderBy' in Prisma

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes