How to Create a self-relation in mapped Table(model of the table didn't exists) in SQLAlchemy

14 Views Asked by At

I have a table 'employee' and I have added it in Metadata and created a mapper class. This employee table didn't have the Alchemy model as it already exists in the DB. Now I want to establish the Self-relation (supervisor) orm support for it.

I have tried these solution, but didn't worked out.

employee = Table("employee", Base.metadata, autoload_with=engine)

class Employee(Base):
    __table__ = employee

    supervisor = relationship('Employee', remote_side=['employee.id'], uselist=False)

0

There are 0 best solutions below