Below, you can see a code that represents the connection between two tables: authors and their books.
from sqlalchemy.orm import relationship
class Author(Base):
__tablename__ = "author"
id = Column(Integer, primary_key=True, autoincrement="auto")
username = Column(String(255), unique=True, nullable=False)
first_name = Column(String(255))
last_name = Column(String(255))
class Book(Base):
__tablename__ = "book"
id = Column(Integer, primary_key=True, index=True)
author_id = Column(Integer, ForeignKey("author.id"))
book_name = Column(String(255), nullable=False)
author = relationship("Author")
What type of relationship is this?
Pay attention to where relationship() is declared.