2

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)

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.