sqlalchemy select rows ordered by dependency

71 Views Asked by At

I have a self referencing table like the following:

class Employee(Base):
    __tablename__ = "t_employee"

    id = sa.Column(BigInteger, sa.Sequence('%s_id_seq' % __tablename__), primary_key=True, nullable=False)
    manager_id = sa.Column(BigInteger, sa.ForeignKey("t_employee.id", ondelete='SET NULL'))

I want to select all rows ordered by their dependency (much like metadata.sorted_tables does for tables). E.g - each manager should come before his employees

Any help is appreciated.

0

There are 0 best solutions below