SQLAlchemy - Mapper configuration and declarative base
我正在编写一个多媒体存档数据库后端,我想使用联合表继承。我将python与sqlacalchemy一起使用声明性扩展。保存媒体记录的表如下:
1 2 3 4 5 6 7 8 9 10 11 | _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)) |
1 2 | mapper(Record, records, polymorphic_on=records.c.type, polymorphic_identity='record') mapper(AudioRecord, audiorecords, inherits=Record, polymorphic_identity='audio_record') |
号
如何将
谢谢你简
我终于在手册中找到了答案。
http://www.sqlachemy.org/docs/05/reference/ext/declarative.html联接表继承