How can I convert django's multi table inheritance schema to an SQLAlchemy model?
It seems like the SQLAlchemy joined table inheritance method needs a discriminator column on the parent table. With Django's multi table inheritance, there is no such field.
class CommonParent(models.Model):
field = models.CharField(max_length=10)
class ChildA(CommonParent):
pass
class ChildB(CommonParent):
pass
This results in 3 tables: ChildA, ChildB, and CommonParent. The child tables have an automatic foreign key added which is (parent class name)_ptr. Django uses this to pull the parent table columns.
With Django, a single ChildA instance results in a JOIN on the CommonParent table and all fields are merged into the class instance.
How can I replicate this behavior through an SQLAlchemy introspected model?
Any pointers in the right direction would help greatly.
Update:
In other words, I need the above django model relationship to be accessible through SQLAlchemy by calling
child_b = ChildB.query.first()
assert hasattr(child_b, 'field') # field is from the parent table, `CommonParent`
In the same way I can do so with Django ORM:
child_b = ChildB.objects.latest()
assert hasattr(child_b, 'field')