SqlAlchemy - Filtering by Relationship Attribute

后端 未结 5 698
日久生厌
日久生厌 2020-12-07 13:09

I don\'t have much experience with SQLAlchemy and I have a problem, which I can\'t solve. I tried searching and I tried a lot of code. This is my Class (reduced to the most

5条回答
  •  情书的邮戳
    2020-12-07 13:41

    I used it with sessions, but an alternate way where you can access the relationship field directly is

    db_session.query(Patient).join(Patient.mother) \
        .filter(Patient.mother.property.mapper.class_.phenoscore==10)
    

    I have not tested it, but I guess this would also work

    Patient.query.join(Patient.mother) \
        .filter(Patient.mother.property.mapper.class_.phenoscore==10)
    

提交回复
热议问题