Open micoloth opened 2 years ago
Adding another example with SQLModel (which subclasses Pydantic's BaseModel
and SQLAlchemy's DeclarativeMeta
avoiding the need to declare model and schema separately).
The above example would look something like this. The tables are set up properly, but the API doesn't show neither authors
nor books
fields.
from sqlmodel import SQLModel, Field, Relationship
# link table
class BookAuthor(SQLModel, table=True):
book: int = Field(primary_key=True, foreign_key='book.id')
author: int = Field(primary_key=True, foreign_key='author.id')
class Book(SQLModel, table=True):
id: int = Field(primary_key=True)
title: str
authors: list['Author'] = Relationship(
back_populates='books',
link_model=BookAuthor,
)
class Author(SQLModel, table=True):
id: int = Field(primary_key=True)
name: str
books: list[Book] = Relationship(
back_populates='authors',
link_model=BookAuthor,
)
Hi, i have the same issue, did you find any solution?
Hi! I'm trying to understand if fastapi_crudrouter supports inserting object with nested fields that represent many-to-many relatioships, via the Sqlalchemy ORM.
This is the code I have:
But if one goes to
http://127.0.0.1:8000/docs
and then toPOST/ Books
, in the "Try it out" feature, and adds this set of data:It doesn't work, it returns this error:
I wanted to understand if I'm doing something wrong, or this use case is not supported by fastapi_crudrouter.
Thanks!