Bird
0
0

Which of the following is the correct way to define a repository class method to get all users in Flask?

easy📝 Syntax Q12 of 15
Flask - Ecosystem and Patterns
Which of the following is the correct way to define a repository class method to get all users in Flask?
Adef get_all_users(): return User.query.all()
Bdef get_all_users(self): return User.query.all()
Cdef get_all_users(self): return User.all()
Ddef get_all_users(self): return User.query.get_all()
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature in a class

    Repository methods inside a class must have self as the first parameter.
  2. Step 2: Verify correct SQLAlchemy query syntax

    To get all records, use User.query.all(). Other options use incorrect method names or miss self.
  3. Final Answer:

    def get_all_users(self): return User.query.all() -> Option B
  4. Quick Check:

    Method with self + User.query.all() = correct [OK]
Quick Trick: Repository methods need self and correct query syntax [OK]
Common Mistakes:
MISTAKES
  • Omitting self parameter in method
  • Using wrong query method like User.all()
  • Using User.query.get_all() which doesn't exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes