SQLAlchemy | Limit join result to one row for one-to-many relationship
问题 I have two entities: Projects and Student Lists. One Project can have many Student lists. I am attempting to join student list on project and only return the first row for each project based on custom ordering of student lists. Attempted Subquery: _whens = {ProjectStatus.APPROVED: 1, ProjectStatus.REJECTED: 2, ProjectStatus.SUBMITTED: 3, None: 4} sort_order = case(value=StudentList.student_list_status_id, whens=_whens) return self._session.query(StudentList). filter(StudentList.student_list