Filter SQLAlchemy query result object's one-to-many attribute

后端 未结 2 1629
孤独总比滥情好
孤独总比滥情好 2021-01-02 10:04

Say I have a couple objects, having a one-to-many relationship, something like

class Parent():
    //id, other cols, etc
    children = relationship(\"Child\         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 10:32

    You try to get two answers in one query. Either you can ask for all parents that have a type-a-child or you can ask for all type-a-children. In the first case, you have to filter the children again, if you want the corresponding children, in the second case you can simple get the corresponding parents. But which way is the correct one, depends on the further problem, you try to solve.

提交回复
热议问题