igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
530 stars 32 forks source link

nested model #89

Closed matv864 closed 1 month ago

matv864 commented 1 month ago

I try to create api on sqlmodel with relationships (In my case, I have table Card and Article with link to Card (key: card_id)) one-to-many

And now I try to understand how it works (joined isn't my solving, I need record which contain Card model with list of Article models inside) image

code of getting record

return await card_crud.get(
                db=db,
                id=card_id,
                schema_to_select=Card_schema,
            )

result of this response image

Why "true" ....? How did it appeared ....?

how can I implement this?

matv864 commented 1 month ago

in Usual SQL I would use this selectinload

but how can I make this in FastCRUD

igorbenav commented 1 month ago

I think what you are looking for is the get_joined method.

Here's a comprehensive guide to joins in FastCRUD, including nested joins