Skip to content

Commit bbc031d

Browse files
committed
Edits
1 parent 394b48f commit bbc031d

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed

django_mongodb_backend/fields/embedded_model_array.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def as_mql(self, compiler, connection):
127127
return {"$anyElementTrue": lhs_mql}
128128

129129

130-
@_EmbeddedModelArrayOutputField.register_lookup
131-
class EmbeddedModelArrayFieldIn(EmbeddedModelArrayFieldBuiltinLookup, lookups.In):
130+
class ArrayAggregationSubqueryMixin:
132131
def get_subquery_wrapping_pipeline(self, compiler, connection, field_name, expr):
133132
return [
134133
{
@@ -165,6 +164,13 @@ def get_subquery_wrapping_pipeline(self, compiler, connection, field_name, expr)
165164
]
166165

167166

167+
@_EmbeddedModelArrayOutputField.register_lookup
168+
class EmbeddedModelArrayFieldIn(
169+
EmbeddedModelArrayFieldBuiltinLookup, lookups.In, ArrayAggregationSubqueryMixin
170+
):
171+
pass
172+
173+
168174
@_EmbeddedModelArrayOutputField.register_lookup
169175
class EmbeddedModelArrayFieldExact(EmbeddedModelArrayFieldBuiltinLookup, lookups.Exact):
170176
pass
@@ -200,45 +206,12 @@ class EmbeddedModelArrayFieldLessThanOrEqual(
200206

201207

202208
@_EmbeddedModelArrayOutputField.register_lookup
203-
class EmbeddedModelArrayFieldAll(EmbeddedModelArrayFieldBuiltinLookup, Lookup):
209+
class EmbeddedModelArrayFieldAll(
210+
EmbeddedModelArrayFieldBuiltinLookup, Lookup, ArrayAggregationSubqueryMixin
211+
):
204212
lookup_name = "all"
205213
get_db_prep_lookup_value_is_iterable = False
206214

207-
def get_subquery_wrapping_pipeline(self, compiler, connection, field_name, expr):
208-
return [
209-
{
210-
"$facet": {
211-
"group": [
212-
{"$project": {"tmp_name": expr.as_mql(compiler, connection)}},
213-
{
214-
"$unwind": "$tmp_name",
215-
},
216-
{
217-
"$group": {
218-
"_id": None,
219-
"tmp_name": {"$addToSet": "$tmp_name"},
220-
}
221-
},
222-
]
223-
}
224-
},
225-
{
226-
"$project": {
227-
field_name: {
228-
"$ifNull": [
229-
{
230-
"$getField": {
231-
"input": {"$arrayElemAt": ["$group", 0]},
232-
"field": "tmp_name",
233-
}
234-
},
235-
[],
236-
]
237-
}
238-
}
239-
},
240-
]
241-
242215
def as_mql(self, compiler, connection):
243216
lhs_mql = process_lhs(self, compiler, connection)
244217
values = process_rhs(self, compiler, connection)

0 commit comments

Comments
 (0)