I have a class structure that looks similar to the below. The table that sqlalchemy creates with db.create_all looks good. Jobs are added with the appropriate columns filled out (school_id for Teachers, precinct_id for Policemen). My problem comes when trying to call do_stuff():
p = Teacher(...)
p.do_stuff()
returns "hey im the parent", which is the return value of Job. So even though everything is being inserted into the DB properly, it seems like the actual inheritance is not occurring but rather the only Model that is in place is a Job model. Is there a way to fix this or should I set this up in another way?
class Job(db.Model):
id = Column(Integer, primary_key=True)
...
def __init__(...):
...
def do_stuff(self):
print 'hey im the parent'
class Teacher(Job):
school_id = Column(Integer, ForeignKey('school.id'))
def __init__(...):
super(Teacher, self).__init__(...)
self.school_id = school_id
def do_stuff(self):
print 'teacher here'
class Policeman(Job):
precinct_id = Column(Integer, ForeignKey'precinct.id'))
def __init__(...):
super(Policeman, self).__init__(...)
self.precinct_id = precinct_id
def do_stuff(self):
print 'police ack'
__mapper_args__and__tablename__you use.