row_registry
Per-query identity map used when materializing joined database rows into models.
RowRegistry
Per-query identity map used while materializing joined rows.
A model reached through the same relation path with the same pk is built once and reused by every row it appears in, instead of being constructed per row and merged afterwards. Models below a many-to-many edge are scoped to their parent, because the through instance of that link is stored on the child. Pk-only models of not selected foreign keys are shared the same way. The registry lives only for one result set.
Attributes:
| Name | Type | Description |
|---|---|---|
instances |
dict[RegistryKey, Model]
|
built models keyed by |
subtree_has_multi |
dict[tuple[type, str], bool]
|
memo of whether the relations selected below a
|
Source code in ormar/models/row_registry.py
| Python | |
|---|---|
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 | |
__init__()
Initialize an empty registry.
Source code in ormar/models/row_registry.py
| Python | |
|---|---|
34 35 36 37 38 39 | |
selects_multi_relation(model_cls, related_models)
Check if selected relations below a model contain a reverse foreign key or a many-to-many relation, which are the only relations that a repeated row of an already built model can still add new children to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_cls
|
type[NewBaseModel]
|
model from which the selected relations start |
required |
related_models
|
Any
|
selected relations as list or nested dict |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if any selected relation on any level is multi or virtual |
Source code in ormar/models/row_registry.py
| Python | |
|---|---|
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |