Update joined table via SQLAlchemy ORM using session.query

前端 未结 2 647
一整个雨季
一整个雨季 2021-02-13 19:58

Working with MySQL, I\'d like to generate this SQL:

UPDATE tableA
INNER JOIN tableB
ON tableA.some_id = tableB.some_id
SET tableA.foo = 1
WHERE tableB.bar IN (\'         


        
2条回答
  •  醉酒成梦
    2021-02-13 20:20

    I think I had exactly the same problem. Here is my solution:

    query = update(Model).values(field=123)
    query = query.where(Model.parent_model_id == ParentModel.id)
    query = query.where(ParentModel.grand_parent_id == GrandParentModel.id)
    query = query.where(GrandParentModel.name == 'foobar')
    session.execute(query)
    

提交回复
热议问题