-
Notifications
You must be signed in to change notification settings - Fork 11
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
add support for subqueries (Subquery, Exists, and QuerySet as a lookup value) #149
add support for subqueries (Subquery, Exists, and QuerySet as a lookup value) #149
Conversation
c848f5b
to
101fe23
Compare
django_mongodb/expressions.py
Outdated
from_table = next( | ||
e.table_name for alias, e in self.alias_map.items() if self.alias_refcount[alias] | ||
) | ||
subquery.lookup_data = { |
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.
The name lookup_data does not readily indicate its purpose and I don't see any explanatory comments about it.
@@ -581,7 +613,7 @@ def _get_ordering(self): | |||
return tuple(fields), sort_ordering, tuple(extra_fields) | |||
|
|||
def get_where(self): | |||
return self.where | |||
return getattr(self, "where", self.query.where) |
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.
So we are back to getattr()
for this... maybe we should drop the get_where()
hook we previously added to try to avoid it. Those could be done in a follow up though. For now, perhaps a comment is warranted.
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.
okey.
bf5230b
to
d97a3d4
Compare
django_mongodb/compiler.py
Outdated
for expr in having_group_by: | ||
group_expressions.add(expr) | ||
if isinstance(self.query.group_by, tuple | list): | ||
group_expressions |= set(self.query.group_by) | ||
elif self.query.group_by is None: | ||
group_expressions = set() | ||
expressions.add(expr) | ||
return self.collapse_group_by(expressions, having_group_by) |
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.
What is the purpose of collapse_group_by
if we already have having_group_by
getting added to the expressions set?
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.
The logic is taken from here and the idea is to avoid repeating expressions and merge both aggregators.
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.
Re-reading I figured out that we haven't defined allows_group_by_selected_pks
so there is not need to call this function (actually this function does nothing)
@@ -269,7 +296,7 @@ def where_node(self, compiler, connection): | |||
raise FullResultSet | |||
|
|||
if self.negated and mql: | |||
mql = {"$eq": [mql, {"$literal": False}]} | |||
mql = {"$not": mql} |
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.
should this be treated as a separate change?
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, maybe. But It was hard to debug when I got those {eq: [big_expression, False]}
96115d6
to
4654f21
Compare
Subquery, Exists, and QuerySet as a lookup value.
7e6f435
to
e971120
Compare
Add support for subqueries