Open iancleary opened 1 year ago
https://fastapi.tiangolo.com/tutorial/sql-databases/#create-the-relationships
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String from sqlalchemy.orm import relationship class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) email = Column(String, unique=True, index=True) hashed_password = Column(String) is_active = Column(Boolean, default=True) lists = relationship("ListObject", back_populates="owner") class ListObject(Base): ... owner_id:int = Column(Integer, ForeignKey("users.id")) sections = relationship("SectionObject", back_populates="lists") class SectionObject(Base): ... list_id:int = Column(Integer, ForeignKey("lists.id")) items = relationship("ItemObject", back_populates="section") class ItemObject(Base): ... section_id:int = Column(Integer, ForeignKey("sections.id"))
Added the question tag to see if I want to do this or not, so call it an idea to look into later
https://fastapi.tiangolo.com/tutorial/sql-databases/#create-the-relationships