如何在多一关系中相交的值SQLalchemy?
我有表<代码>老师。它包含与表student
的多一关系。学生包含唯一的列名称
。我如何找到包含某些名字的学生的所有老师?
例如:
Tothert1包含学生1名称“鲍勃”和sut剂品2的学生。
thoston2包含带名称为“ alice”和sut剂的sut剂品的Student2和名称为“ mark”的Student3。
thoston3包含名称为“鲍勃”的Student1。
thoston4包含名称为“ mark”的Student3。
我得到名称[“ Alice”,“ Mark”]
。
在此示例中,我必须得到老师1、2、4。
如何编写此Sqlalchemy查询?session.query(offer).filter(...)。所有()
?
I have table Teacher
. It contains many-to-many relationship with table Student
. Student contains unique column name
. how can I find all the teachers that contain students with certain names?
For example:
Teacher1 contains Student1 with name "Bob" and Student2 with name "Alice".
Teacher2 contains Student2 with name "Alice" and Student3 with name "Mark".
Teacher3 contains Student1 with name "Bob".
Teacher4 contains Student3 with name "Mark".
I get names ["Alice", "Mark"]
.
In this example I have to get Teacher 1, 2, 4.
How to write this sqlalchemy query?session.query(Teacher).filter(...).all()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
避免您的协会多一对多的模型/TABELE是
studentTeacher
,并且您正在寻找names =(“ Alice”,“ Mark”,)
,此查询应返回什么您期望:Asumming that your association many-to-many model/tabele is
StudentTeacher
and you looking fornames=("Alice", "Mark",)
, this query should return what you expected: