Skip to content

Commit

Permalink
use polymoprhic table GenericReading
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Jun 5, 2017
1 parent d7c94c8 commit 1d4061c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions unihan_db/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,34 @@ class kMandarin(Base):
char = relationship("Unhn")


class kHanyuPinyin(Base):
__tablename__ = 'kHanyuPinyin'
class GenericReading(Base):
__tablename__ = 'GenericReading'
id = Column(Integer, primary_key=True)
char_id = Column(Integer, ForeignKey('Unhn.id'))
type = Column(String(50))
locations = relationship("UnhnLocation")
readings = relationship("UnhnReading")

char = relationship("Unhn")
__mapper_args__ = {
'polymorphic_identity': 'generic_reading',
'polymorphic_on': type
}


class kHanyuPinyin(GenericReading):
__tablename__ = 'kHanyuPinyin'
__mapper_args__ = {
'polymorphic_identity': 'kHanyuPinyin',
}

id = Column(Integer, ForeignKey('GenericReading.id'), primary_key=True)


class UnhnLocation(Base):
__tablename__ = 'UnhnLocation'
id = Column(Integer, primary_key=True)
kHanyuPinyin_id = Column(Integer, ForeignKey('kHanyuPinyin.id'))
generic_reading_id = Column(Integer, ForeignKey('GenericReading.id'))
volume = Column(Integer)
page = Column(Integer)
character = Column(Integer)
Expand All @@ -98,5 +112,5 @@ class UnhnLocation(Base):
class UnhnReading(Base):
__tablename__ = 'UnhnReading'
id = Column(Integer, primary_key=True)
kHanyuPinyin_id = Column(Integer, ForeignKey('kHanyuPinyin.id'))
generic_reading_id = Column(Integer, ForeignKey('GenericReading.id'))
reading = Column(String(24))

0 comments on commit 1d4061c

Please sign in to comment.