Skip to content

Commit 83ecb53

Browse files
committed
Add expression wrap to parameters.
1 parent 7a8136a commit 83ecb53

File tree

5 files changed

+163
-106
lines changed

5 files changed

+163
-106
lines changed

django_mongodb_backend/expressions/builtins.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def case(self, compiler, connection):
5454
}
5555

5656

57-
def col(self, compiler, connection): # noqa: ARG001
57+
def col(self, compiler, connection, as_path=False): # noqa: ARG001
5858
# If the column is part of a subquery and belongs to one of the parent
5959
# queries, it will be stored for reference using $let in a $lookup stage.
6060
# If the query is built with `alias_cols=False`, treat the column as
@@ -72,7 +72,11 @@ def col(self, compiler, connection): # noqa: ARG001
7272
# Add the column's collection's alias for columns in joined collections.
7373
has_alias = self.alias and self.alias != compiler.collection_name
7474
prefix = f"{self.alias}." if has_alias else ""
75-
return f"${prefix}{self.target.column}"
75+
return f"{prefix}{self.target.column}" if as_path else f"${prefix}{self.target.column}"
76+
77+
78+
def col_as_path(self, compiler, connection):
79+
return col(self, compiler, connection).lstrip("$")
7680

7781

7882
def col_pairs(self, compiler, connection):
@@ -94,8 +98,11 @@ def expression_wrapper(self, compiler, connection):
9498
return self.expression.as_mql(compiler, connection)
9599

96100

97-
def f(self, compiler, connection): # noqa: ARG001
98-
return f"${self.name}"
101+
def f(self, compiler, connection, as_path=False):
102+
expression = self.resolve_expression(compiler.query)
103+
if as_path:
104+
return expression.as_mql(compiler, connection, as_path=as_path)
105+
return expression.as_mql(compiler, connection)
99106

100107

101108
def negated_expression(self, compiler, connection):

0 commit comments

Comments
 (0)