Inheritance + Foreign Keys
class Subscription(db.Model): 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) billing_system_id = db.Column( db.Integer, db.ForeignKey('public.billing_system.id') ) billing_system = db.relationship('BillingSystem', backref='subscriptions')
So what I have done is:
1 ) Shifted the Subscription.billing_system_id Foreign Key up to the Base Subscription Model2 ) Added in the Subscription.billing_system Relationship
So now I am doing this:
>>> o = BillingSystem.query.get(1)>>> a = Product1()>>> a.billing_system_id = o.id
Which results in:
>>> a.billing_system.subscriptions[<cPanel Hosting Reseller: 2>]>>> a.billing_system_id2
So unless I am doing something wrong here, it seems to work. I just can't pass the actual BillingSystem object, I actually have to set the ID. It is still referencially enforced when the model is saved though, so I don't see too many issues with it.
Thanks for your help :)