mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
some comments and fixes
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
from typing import Optional, List
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
# Relationship model
|
||||
class AuthorBookLink(SQLModel, table=True):
|
||||
author_id: int | None = Field(default=None, foreign_key="author.id", primary_key=True)
|
||||
book_id: int | None = Field(default=None, foreign_key="book.id", primary_key=True)
|
||||
|
||||
# Author model
|
||||
class Author(SQLModel, table=True):
|
||||
id: Optional[int] = Field(primary_key=True, index=True)
|
||||
name: str
|
||||
|
||||
books: List["Book"] = Relationship(back_populates="authors", link_model=AuthorBookLink)
|
||||
|
||||
# Book model
|
||||
class Book(SQLModel, table=True):
|
||||
id: Optional[int] = Field(primary_key=True, index=True)
|
||||
title: str
|
||||
|
||||
Reference in New Issue
Block a user