python - 如何判断 InstrumentedAttribute 是否是 sqlalchemy 中的关系?

标签 python sqlalchemy

给定一个 sqlalchemy 模型类

class Table(Base):
  __table__name = 'table'
  col1 = Column(...)

  rel = relationship(...)

如果您查看col1rel 都是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/

相关文章:

python - 为什么 numpy 的 fft 的每一个第二个系数都是其应有的倒数?

python - 插入缺少绑定(bind)参数的 sqlalchemy 错误,但在 Workbench 中有效

python - association_proxy 创建者中的 session

python - Django:快速处理添加不可空字段

python - 在 Django 中使用 Tarantool 和 MySQL

python - 相当于在 tensorflow 中枚举以在 tf.map_fn 中使用索引

php - 如何在php-fpm shell_exec中激活anaconda环境?

python - 在 SQLAlchemy 中执行连接时出错 'Please specify the ' onclause' of this join explicitly'。

python - Flask 和 SqlAlchemy session

python - sqlalchemy.exc.OperationalError : (sqlite3. OperationalError)尝试创建数据库时无法打开数据库文件错误