Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Getting back property of object in a query list SQLAlchemy

I have a join table called UserServices. Which has a FK of service_id and makes a back ref to a service. Below I get all the userServices in which the id in the route param matches the user_id (another FK) I am then trying to access all the service properties on the all_user_services list.

My current code only returns one dict instead of a list of dicts. What am i doing wrong?

@bp.route('/user/<id>/services', methods=['GET'])
def get_services_from_user(id):
    all_user_services = db_session.query(UserService).filter(UserService.user_id == id).all()

    for service in all_user_services:
        result = service_schema.dump(service.service)
        return jsonify(result)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You just return on first for iteration. You need to create result list:

dumped = [service_schema.dump(s.service) for s in all_user_services]
return jsonify(dumped)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!