Skip to content

Commit

Permalink
Advanced CRUD doc update.
Browse files Browse the repository at this point in the history
  • Loading branch information
slaarti committed Jan 24, 2025
1 parent 3e6cee4 commit 427764c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions docs/advanced/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,16 @@ This order ensures that the SQL joins are structured correctly to reflect the ma

Note that the first one can be the model defined in `FastCRUD(Model)`.

??? example "Models"

```python
--8<--
tests/sqlalchemy/conftest.py:model_project
tests/sqlalchemy/conftest.py:model_participant
tests/sqlalchemy/conftest.py:model_proj_parts_assoc
--8<--
```

```python
# Fetch projects with their participants via a many-to-many relationship
joins_config = [
Expand All @@ -626,11 +636,16 @@ joins_config = [
),
]

crud_project = FastCRUD(Project)
project_crud = FastCRUD(Project)

class ReadProjectSchema(BaseModel):
id: int
name: str
description: Optional[str] = None

projects_with_participants = await project_crud.get_multi_joined(
db=db,
schema_to_select=ProjectSchema,
schema_to_select=ReadProjectSchema,
joins_config=joins_config,
)
```
Expand Down

0 comments on commit 427764c

Please sign in to comment.