merge_mixin
MergeModelMixin
Used to merge models instances returned by database, but already initialized to ormar Models.keys
Models can duplicate during joins when parent model has multiple child rows, in the end all parent (main) models should be unique.
Source code in ormar\models\mixins\merge_mixin.py
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
merge_instances_list(result_rows)
classmethod
Merges a list of models into list of unique models.
Models can duplicate during joins when parent model has multiple child rows, in the end all parent (main) models should be unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_rows |
List[Model]
|
list of already initialized Models with child models populated, each instance is one row in db and some models can duplicate |
required |
Returns:
Type | Description |
---|---|
List["Model"]
|
list of merged models where each main model is unique |
Source code in ormar\models\mixins\merge_mixin.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
merge_two_instances(one, other, relation_map=None)
classmethod
Merges current (other) Model and previous one (one) and returns the current Model instance with data merged from previous one.
If needed it's calling itself recurrently and merges also children models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation_map |
Optional[Dict]
|
map of models relations to follow |
None
|
one |
Model
|
previous model instance |
required |
other |
Model
|
current model instance |
required |
Returns:
Type | Description |
---|---|
Model
|
current Model instance with data merged from previous one. |
Source code in ormar\models\mixins\merge_mixin.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|