Flask SqlAlchemy join two models without foreign key MYSQL

前端 未结 4 2316
余生分开走
余生分开走 2021-02-20 11:49

I am joining two models without a foreign key:

Models:

class Users(db.Model):
    __tablename__ = \"Users\"
    userName = db.Column(db.String, primary_k         


        
4条回答
  •  甜味超标
    2021-02-20 12:04

    Its an old post but I had a similar problem

    result = session.query(models.Users).join(models.TimeOff, models.Users.userName == models.TimeOff.userName).all()
    

    with this method, I can reach the features of the first object which is Users but not the TimeOff. I am wondering if it is possible to reach the secondary object's attributes. But I hope this helps.

提交回复
热议问题