我一直在绞尽脑汁,似乎无法解决如何解决这个问题.请注意,我已从模型中删除了大量不相关的字段
我正在编写我的SQL-Alchemy模型,并遇到了以下问题:
由于多个计费系统,每个都有完全不同的属性,并且由于订阅属性的不同类型(即用户名,节点位置等),我不得不走多态继承之路.
class Subscription(Base):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
secret = db.Column(postgresql.BYTEA)
type = db.Column(SubscriptionType.db_type())
status = db.Column(StatusType.db_type())
subscription_id = db.Column(db.Integer)
__tablename__ = 'subscription'
__table_args__ = {'schema':'public'}
__mapper_args__ = {'polymorphic_on' : type}
def __repr__(self):
return '<Subscription: %r>' % self.id
class Product1(Subscription):
__mapper_args__ = {'polymorphic_identity' : SubscriptionType.product1}
id = db.Column(db.Integer, db.ForeignKey('public.subscription.id'),
primary_key = True)
billing_system = db.Column(
db.Integer,
db.ForeignKey('public.billing_system.id')
)
class BillingSystem(Base):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
type = db.Column(BillingSystemType.db_type())
__tablename__ = 'billing_system'
__table_args__ = {'schema':'public'} …Run Code Online (Sandbox Code Playgroud)