merge_mixin
MergeModelMixin
Used to collect models instances returned by database, but already initialized to ormar Models.
Rows of one model returned by a join are materialized into a single shared
instance (see RowRegistry), so the same main model can repeat in the
list of materialized rows; in the end all main models should be unique.
Source code in ormar/models/mixins/merge_mixin.py
| Python | |
|---|---|
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
merge_instances_list(result_rows, *, excludable)
classmethod
Collapses a list of materialized rows into a list of unique models, keeping the order of first occurrence.
Each top-level model also has the queryset's ExcludableItems
attached via the __ormar_excludable__ slot so a bare model_dump()
on the result can resolve the (lazily cached) flatten map without going
back through the queryset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_rows
|
list[Model]
|
list of models materialized from consecutive rows, where rows of the same main model resolve to the same instance |
required |
excludable
|
ExcludableItems
|
ExcludableItems to attach to every top-level
instance via the |
required |
Returns:
| Type | Description |
|---|---|
list["Model"]
|
list of unique main models |
Source code in ormar/models/mixins/merge_mixin.py
| Python | |
|---|---|
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |