我有一个模型Zone
,一个模型Entity
和一个模型Transit
。Transit
最小定义为:
class Entity(db.Model):
__tablename__ = 'entities'
id = db.Column(db.Integer, primary_key=True)
contained_by = db.Column(db.Integer, db.ForeignKey('entities.id'))
contains = db.relationship('Entity', backref='container')
discriminator = db.Column('type', db.String(50))
__mapper_args__ = {'polymorphic_on': discriminator}
class Zone(Entity):
__mapper_args__ = {'polymorphic_identity': 'zones'}
routes = db.relationship('Transit')
(stuff goes here)
class Transit(db.Model):
__tablename__ = "transits"
start = db.Column(db.Integer, db.ForeignKey('zones.id'))
end = db.Column(db.Integer, db.ForeignKey('zones.id'))
Zone
还有一些关于距离和防御性的信息,但这与此无关。
- 首先,由于
Zone
是Entity
使用单表继承的子类,我可以引用zones.id
吗? - 其次,财产会合并
Zone.routes
吗?Transit.start
Transit.end