Skip to content

Commit

Permalink
Add documentation of AssociateUsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ZechCodes committed Nov 7, 2024
1 parent 9348c3f commit 8e1a043
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,30 @@ posts = await user.posts

Lazy fields will only fetch once and then cache the result.

Additionally, `LazyLoadTheRelated` and `LazyLoadEveryRelated` can associate with models using an association model that
has references to model being defined and the model being lazily queried. To do this annotate the referenced model with
`ommi.query_fields.AssociateUsing` which is passed the model that is to be used to associate the models.

```python
@ommi_model
@dataclass
class User:
id: int

permissions: "LazyLoadEveryRelated[Annotated[Permission, AssociateUsing(UserPermission)]]"

@ommi_model
@dataclass
class Permission:
id: int

@ommi_model
@dataclass
class UserPermission:
user_id: Annotated[int, ReferenceTo(User.id)]
permission_id: Annotated[int, ReferenceTo(Permission.id)]
```

#### Get

'LazyQueryFields` provide a `get` method that takes a default value and returns the value of the relationship or the
Expand Down

0 comments on commit 8e1a043

Please sign in to comment.