Flask SqlAlchemy join two models without foreign key MYSQL

前端 未结 4 2310
余生分开走
余生分开走 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:19

    You need to tell SQLAlchemy how to join the tables. Try something like this:

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

提交回复
热议问题