【问题标题】:SQLAlchemy - Mapper configuration and declarative baseSQLAlchemy - 映射器配置和声明性基础
【发布时间】:2010-10-22 00:16:47
【问题描述】:

我正在编写一个多媒体存档数据库后端,我想使用连接表继承。我正在使用带有声明性扩展的 SQLAlchemy 的 Python。保存媒体记录的表如下:

_Base = declarative_base()

class Record(_Base):
    __tablename__ = 'records'

    item_id = Column(String(M_ITEM_ID), ForeignKey('items.id'))
    storage_id = Column(String(M_STORAGE_ID), ForeignKey('storages.id'))
    id = Column(String(M_RECORD_ID), primary_key=True)
    uri = Column(String(M_RECORD_URI))
    type = Column(String(M_RECORD_TYPE))
    name = Column(String(M_RECORD_NAME))

type 列是一个鉴别器。现在我想从Record 类定义子类AudioRecord,但我不知道如何设置多态映射器使用声明性语法。我正在寻找以下代码的等效项(来自 SQLAlchemy 文档):

mapper(Record, records, polymorphic_on=records.c.type, polymorphic_identity='record')
mapper(AudioRecord, audiorecords, inherits=Record, polymorphic_identity='audio_record')

如何将polymorphic_on、polymorphic_identity 和inherits 关键字传递给由声明性扩展创建的映射器?

谢谢 一月

【问题讨论】:

  • 我认为你最好在 SQLAlchemy 邮件列表上询问 Mike,他真的很有帮助。

标签: python sqlalchemy


【解决方案1】:
猜你喜欢
  • 2014-05-06
  • 2015-07-09
  • 2015-02-25
  • 2011-03-28
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 2021-12-18
相关资源
最近更新 更多