|
|
@ -5,11 +5,20 @@ from sqlalchemy.orm import relationship, declarative_base, sessionmaker
|
|
|
|
Base = declarative_base()
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
|
|
|
|
|
|
class Show(Base):
|
|
|
|
class Show(Base):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
relationship(argument, opt1, opt2, ...)
|
|
|
|
|
|
|
|
argument is string of class or Mapped class of the target entity
|
|
|
|
|
|
|
|
backref creates a bi-directional corresponding relationship (back_populates preferred)
|
|
|
|
|
|
|
|
back_populates points to the corresponding relationship (the actual class attribute identifier)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See: https://docs.sqlalchemy.org/en/(14|20)/orm/basic_relationships.html
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
__tablename__ = 'shows'
|
|
|
|
__tablename__ = 'shows'
|
|
|
|
|
|
|
|
|
|
|
|
# v1.x
|
|
|
|
# v1.x
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
|
|
|
|
|
|
|
|
name = Column(String)
|
|
|
|
name = Column(String)
|
|
|
|
year = Column(Integer)
|
|
|
|
year = Column(Integer)
|
|
|
|
|
|
|
|
|
|
|
@ -19,7 +28,9 @@ class Show(Base):
|
|
|
|
# year: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
# year: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
|
|
|
|
|
|
|
|
# v1.x
|
|
|
|
# v1.x
|
|
|
|
|
|
|
|
#patterns = relationship('Pattern', back_populates='show', cascade="all, delete", passive_deletes=True)
|
|
|
|
patterns = relationship('Pattern', back_populates='show', cascade="all, delete")
|
|
|
|
patterns = relationship('Pattern', back_populates='show', cascade="all, delete")
|
|
|
|
|
|
|
|
# patterns = relationship('Pattern', back_populates='show', cascade="all")
|
|
|
|
|
|
|
|
|
|
|
|
# v2.0
|
|
|
|
# v2.0
|
|
|
|
# patterns: Mapped[List["Pattern"]] = relationship(back_populates="show", cascade="all, delete")
|
|
|
|
# patterns: Mapped[List["Pattern"]] = relationship(back_populates="show", cascade="all, delete")
|
|
|
|