views:

685

answers:

1

Hi, I am writing a multimedia archive database backend and I want to use joined table inheritance. I am using Python with SQLAlchemy with the declarative extension. The table holding the media record is as follows:

_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))

The column type is a discriminator. Now I want to define the child class AudioRecord from the Record class, but I don't how to setup the polymorphic mapper using the declarative syntax. I am looking for an equivalent for the following code (from SQLAlchemy documentation):

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

How can I pass the polymorphic_on, polymorphic_identity and inherits keywords to the mapper created by the declarative extension?

Thank you Jan

+1  A: 

Hi, I finally found the answer: RTFM :-)

http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#joined-table-inheritance

honzas