Below, you can see a code that represents the connection between two tables: singers and their songs.
from sqlalchemy.orm import relationship
class Singer(Base):
__tablename__ = "singer"
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))
song_id = Column(Integer, ForeignKey("song.id"))
song = relationship("Song")
class Song(Base):
__tablename__ = "song"
id = Column(Integer, primary_key=True, index=True)
song_name = Column(String(255), nullable=False)
What type of relationship is this?
Pay attention to where relationship() is declared.