-
Notifications
You must be signed in to change notification settings - Fork 27
add support for QuerySet.union() #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Once this code is merged, we should change the: |
5acdf8e
to
70c2b20
Compare
django_mongodb/compiler.py
Outdated
if "_id" not in projected_fields: | ||
combinator_pipeline.append({"$unset": "_id"}) | ||
else: | ||
raise NotSupportedError(f"Combinator {self.query.combinator} isn't supported.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this already checked by supports_select_{self.query.combinator}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when I wrote this code I had in mind the other combinators. But yes, it is being checked twice.
django_mongodb/query.py
Outdated
@@ -166,6 +169,10 @@ def join(self, compiler, connection): | |||
return lookup_pipeline | |||
|
|||
|
|||
def orderby(self, compiler, connection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order_by
(follows the pattern of other function names with multiple words)
django_mongodb/compiler.py
Outdated
@@ -391,6 +398,9 @@ def project_field(column): | |||
if hasattr(column, "target"): | |||
# column is a Col. | |||
target = column.target.column | |||
# Handle Order by columns as refs columns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by -> By
django_mongodb/compiler.py
Outdated
parts.append((compiler_.build_query(columns), compiler_.collection_name)) | ||
|
||
except EmptyResultSet: | ||
# Omit the empty queryset with UNION and with DIFFERENCE if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chop "and with DIFFERENCE"
django_mongodb/compiler.py
Outdated
_, exprs = zip(*columns, strict=True) | ||
columns = tuple(zip(main_query_fields, exprs, strict=True)) | ||
parts.append((compiler_.build_query(columns), compiler_.collection_name)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chop blank line
django_mongodb/compiler.py
Outdated
@@ -32,6 +32,33 @@ def __init__(self, *args, **kwargs): | |||
# A list of OrderBy objects for this query. | |||
self.order_by_objs = None | |||
|
|||
def _unfold_column(self, col): | |||
""" | |||
Flattens a field by returning its target or by replacing dots with GROUP_SEPARATOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 257 verb style: Flatten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool wow, I didn't know about that.
django_mongodb/compiler.py
Outdated
|
||
def _fold_columns(self, unfold_columns): | ||
""" | ||
Converts flat columns into a nested dictionary, grouping fields by table names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert
django_mongodb/features.py
Outdated
@@ -512,6 +517,7 @@ def django_test_expected_failures(self): | |||
"delete.tests.DeletionTests.test_only_referenced_fields_selected", | |||
"lookup.tests.LookupTests.test_in_ignore_none", | |||
"lookup.tests.LookupTests.test_textfield_exact_null", | |||
"queries.test_qs_combinators.QuerySetSetOperationTests.test_exists_union", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems useful except for the SQL introspection part, so I comment out the unneeded lines in the latest commit on the Django fork.
b68183f
to
fee311a
Compare
Done in #123 |
fee311a
to
df2cddd
Compare
fixes #72