1
나는 SQLAlchemy 문서를 읽고있다 주어진 예를 혼동 얻을 :SQLAlchemy에서 인접 목록 관계는 어떻게 작동합니까?
class Node(Base):
__tablename__ = 'node'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('node.id'))
data = Column(String(50))
children = relationship("Node")
나는 노드 객체가이 클래스 정의에 의해 많은 아이를 가질 수있어. 내 이해는 노드 객체를 만들고 저장할 때 레코드 (id, parent_id, data)가 데이터베이스에 삽입 될 때, 나는 id
이 기본적으로 생성된다는 것을 알지만 어떻게 parent_id
이 생성됩니까? 내 프로젝트에서 비슷한 사용법을 시도했지만 parent_id
은 None
으로 유지됩니다.