Bird
0
0

Given the code:

medium📝 component behavior Q4 of 15
Flask - Performance Optimization
Given the code:
users = User.query.options(joinedload(User.posts)).filter(User.active == True).all()

What is the effect of joinedload(User.posts) here?
AIt limits the number of posts loaded per user
BIt filters users who have posts
CIt delays loading posts until accessed
DIt loads all posts related to each user in the same query
Step-by-Step Solution
Solution:
  1. Step 1: Understand joinedload usage

    joinedload(User.posts) tells SQLAlchemy to load related posts with users in one query using SQL JOIN.
  2. Step 2: Analyze other options

    It does not filter users, delay loading, or limit posts count.
  3. Final Answer:

    It loads all posts related to each user in the same query -> Option D
  4. Quick Check:

    joinedload eager loads related data = A [OK]
Quick Trick: joinedload fetches related data immediately in one query [OK]
Common Mistakes:
MISTAKES
  • Thinking joinedload filters data
  • Confusing joinedload with lazy loading
  • Assuming it limits related records

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes