【发布时间】:2023-03-24 13:28:01
【问题描述】:
我有一个问题,我确信它会很快回答,但我无法通过谷歌搜索找到它......
我有一个使用声明性 SqlAlchemy 定义的类 Product:
class Product(declarativeBase):
__tablename__ = "products"
_brand = Column("brand", Unicode(128))
_series = Column("series", String(128))
_price = Column("price", Float)
_description = Column("description", UnicodeText)
_manufacturerId = Column("manufacturer_id", Integer, ForeignKey("manufacturers.id"), key="manufacturerId")
_manufacturer = relationship("Manufacturer",
uselist=False,
backref=backref("_products", collection_class=set)
)
在某一点上,我想获取所有产品的一些列,例如 _brand 和 _manufacturerId,但我不想将其命名为 _manufacturerId,而是将其命名为 _manufacturer(主要是为了“隐藏”关系)。
我不知道该怎么做......它会是这样的:
session.query(Product.Product._brand, Product.Product._manufacturerId as "_manufacturer").all()
我很确定这是可行的,但我不知道如何(使用 sqlalchemy 0.6.6,以防万一)
非常感谢!
【问题讨论】:
标签: python sqlalchemy