python - 如何在 sqlalchemy 中的 query() 中不指定的情况下使用 from table ?

标签 python sqlalchemy

以下是我的 sqlalchemy 内连接代码。我不想选择订单表的任何列,但我也需要订单作为我的来源表。

query = db.session.query(Order, Customer.first_name, Customer.cnic_no, Item.name, Item.category)
query = query.join(Customer)
result = query.join(Item)

最佳答案

使用select_from

query = db.session.query(Customer.first_name, Customer.cnic_no, Item.name, Item.category)
query = query.select_from(Order)
query = query.join(Customer)
result = query.join(Item)

关于python - 如何在 sqlalchemy 中的 query() 中不指定的情况下使用 from table ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58843368/

相关文章:

python - tkinter gui 编程中的 AttributeError

java - 为什么我无法通过套接字接收数据

Python/SQLAlchemy 迁移 - 迁移数据库中的更改时出现 "ValueError: too many values to unpack"

postgresql - SQlAlchemy 批量插入对 postgresql 连接字符串占用了太多时间

python - Flask-SQLAlchemy 超时错误

python - Flask/Gunicorn 有 4 个 worker : Does long polling block a worker?

python - 将文件从文件夹复制到Python文件夹

SQLAlchemy,我什么时候提交?

python - StaticText 项目在 wx.StaticBox 中消失

python - SQLAlchemy 属性错误 : 'module' object has no attribute 'PandasSQLAlchemy'