给定一个 sqlalchemy 模型类
class Table(Base):
__table__name = 'table'
col1 = Column(...)
rel = relationship(...)
如果您查看表,col1 和rel 都是InstrumentedAttribute
类型。我怎样才能区分这两个?我试图研究它们的属性。但是太多了……而且没有关于这件事的文档。
最佳答案
检查 Table.<column>.property
的类型它通常可以是 ColumnProperty 或 RelationshipProperty 的实例:
>>> type(Table.col1.property)
<class 'sqlalchemy.orm.properties.ColumnProperty'>
>>> type(Table.rel.property)
<class 'sqlalchemy.orm.relationships.RelationshipProperty'>
关于python - 如何判断 InstrumentedAttribute 是否是 sqlalchemy 中的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26572268/