Skip to content

Commit 7f450a7

Browse files
committed
Edits.
1 parent 2c48d11 commit 7f450a7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

django_mongodb_backend/expressions/builtins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def ref(self, compiler, connection, as_path=False): # noqa: ARG001
172172

173173
@property
174174
def ref_is_simple_column(self):
175-
return isinstance(self.source, Col) and self.source.alias is not None
175+
return self.source.is_simple_column
176176

177177

178178
def star(self, compiler, connection, as_path=False): # noqa: ARG001

django_mongodb_backend/fields/embedded_model_array.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.utils.functional import cached_property
99

1010
from .. import forms
11+
from ..lookups import builtin_lookup_path
1112
from ..query_utils import process_lhs, process_rhs
1213
from . import EmbeddedModelField
1314
from .array import ArrayField, ArrayLenTransform
@@ -141,6 +142,9 @@ def as_mql_expr(self, compiler, connection):
141142
)
142143
return {"$anyElementTrue": lhs_mql}
143144

145+
def as_mql_path(self, compiler, connection):
146+
return builtin_lookup_path(self, compiler, connection)
147+
144148

145149
@_EmbeddedModelArrayOutputField.register_lookup
146150
class EmbeddedModelArrayFieldIn(EmbeddedModelArrayFieldBuiltinLookup, lookups.In):

tests/model_fields_/test_embedded_model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ def test_nested(self):
225225
)
226226
self.assertCountEqual(Book.objects.filter(author__address__city="NYC"), [obj])
227227

228+
def test_annotate(self):
229+
obj = Book.objects.create(
230+
author=Author(name="Shakespeare", age=55, address=Address(city="NYC", state="NY"))
231+
)
232+
book_from_ny = (
233+
Book.objects.annotate(city=F("author__address__city")).filter(city="NYC").first()
234+
)
235+
self.assertCountEqual(book_from_ny.city, obj.author.address.city)
236+
228237

229238
class ArrayFieldTests(TestCase):
230239
@classmethod

0 commit comments

Comments
 (0)