I encountered in a book some explanation how self referential tables in SQLAlchemy (Python) work, as an example, here is the class Employee with a manager_id:
class Employee(Base):
__tablename__ = 'employees'
id = Column(Integer(), primary_key=True)
manager_id = Column(Integer(), ForeignKey('employees.id'))
name = Column(String(255), nullable=False)
manager = relationship("Employee", backref=backref('reports'),
remote_side=[id])
unfortunately, I still don't really understand how this works.. In this case I guess every Employee can be a manager (with a manager_id) and Employee contains a reference to a manager, but what means backref=backref('reports') and what is reports? Is it another table? and what is remote_side=[id] in this case? does it reference to the employer.id, so to say that your manager manages some specific employer.id or the other way around, that each employer.id has some manager with a manager_id?
backref
- that and the texts around it should answer all your questions :)