18 lines
721 B
Python
18 lines
721 B
Python
from typing import List
|
|
from sqlalchemy import String, ForeignKey
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
from crudkit import CrudMixin
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
class Author(CrudMixin, Base):
|
|
__tablename__ = "author"
|
|
name: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
books: Mapped[List["Book"]] = relationship(back_populates="author", cascade="all, delete-orphan")
|
|
|
|
class Book(CrudMixin, Base):
|
|
__tablename__ = "book"
|
|
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
author_id: Mapped[int] = mapped_column(ForeignKey("author.id"), nullable=False)
|
|
author: Mapped[Author] = relationship(back_populates="books")
|