I do not have much experience with SQLAlchemy, and I have a problem that I cannot solve. I tried to search and I tried a lot of code. This is my class (shortened to the most significant code):
class Patient(Base): __tablename__ = 'patients' id = Column(Integer, primary_key=True, nullable=False) mother_id = Column(Integer, ForeignKey('patients.id'), index=True) mother = relationship('Patient', primaryjoin='Patient.id==Patient.mother_id', remote_side='Patient.id', uselist=False) phenoscore = Column(Float)
and I would like to interview all patients whose mother is a fenoscor (for example) == 10
As I said, I tried a lot of code, but I donβt understand. A logical decision, in my opinion, would be
patients = Patient.query.filter(Patient.mother.phenoscore == 10)
because you can access .mother.phenoscore for each element in the output, but this code does not.
Is there a (direct) ability to filter by attribute of a relation (without writing an SQL statement or an additional join statement), I need a filter of this type more than once.
Even if there is no easy solution, I will be happy to receive all the answers.
python filter foreign-keys sqlalchemy foreign-key-relationship
user1105851 Dec 19 '11 at 12:35 2011-12-19 12:35
source share