Skip to content

Commit 82b2097

Browse files
WaVEVtimgraham
authored andcommitted
Add EmbeddedModelArrayFieldTransform.VIRTUAL_COLUMN_PREFIX
1 parent e21140a commit 82b2097

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

django_mongodb_backend/fields/embedded_model_array.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,14 @@ class EmbeddedModelArrayFieldLessThanOrEqual(
227227

228228
class EmbeddedModelArrayFieldTransform(Transform):
229229
field_class_name = "EmbeddedModelArrayField"
230+
VIRTUAL_COLUMN_PREFIX = "item"
230231

231232
def __init__(self, field, *args, **kwargs):
232233
super().__init__(*args, **kwargs)
233234
# Lookups iterate over the array of embedded models. A virtual column
234235
# of the queried field's type represents each element.
235236
column_target = field.clone()
236-
column_name = f"$item.{field.column}"
237+
column_name = f"${self.VIRTUAL_COLUMN_PREFIX}.{field.column}"
237238
column_target.db_column = column_name
238239
column_target.set_attributes_from_name(column_name)
239240
self._lhs = Col(None, column_target)
@@ -283,7 +284,7 @@ def as_mql(self, compiler, connection):
283284
{
284285
"$map": {
285286
"input": lhs_mql,
286-
"as": "item",
287+
"as": self.VIRTUAL_COLUMN_PREFIX,
287288
"in": inner_lhs_mql,
288289
}
289290
},

django_mongodb_backend/fields/polymorphic_embedded_model_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, field, *args, **kwargs):
9898
# Lookups iterate over the array of embedded models. A virtual column
9999
# of the queried field's type represents each element.
100100
column_target = field.clone()
101-
column_name = f"$item.{field.column}"
101+
column_name = f"${self.VIRTUAL_COLUMN_PREFIX}.{field.column}"
102102
column_target.name = f"{field.name}"
103103
column_target.db_column = column_name
104104
column_target.set_attributes_from_name(column_name)

0 commit comments

Comments
 (0)