在 Sqlalchemy 上连接表时是否应指定所有键名

Should all key names be specified when tables join on Sqlalchemy

示例表如下:

1. 学生
学生 ID -- PK
学生姓名
collegeID

2. 大学
collegeID -- PK
学院名称

我想获得所有学生的关键值和所有大学的关键值

这是 sqlalchemy 查询示例。

from example.database import dao
    ...
    ...
    example = dao.query(students).\
          join(colleges, 
               students.collegeID == colleges.collegeID).\
          all()

但它没有 collegeName 数据。只有学生数据。
所以我不得不改变它。

example = dao.query(students.studentID, 
                students.studentName,
                stduents.collegeID,
                colleges.collegeName).\
          join(colleges, students.collegeID == colleges.collegeID).\
          all()

如何在不指定我想要的所有键的情况下更轻松快捷地完成此操作。

example = (dao.query(students, colleges)
    .join(colleges, students.collegeID == colleges.collegeID)
    ).all()

for student, college in example:
    print(student, college)

这将 return 一个元组值列表:

 <student-1, college-1>
 <student-1, college-2>
 ...
 <student-N, college-?>