Skip to content

Commit

Permalink
Refactor base_table and collection_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV committed Nov 21, 2024
1 parent e543e0f commit 176cd33
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,24 @@ def project_field(column):
@cached_property
def base_table(self):
return next(
v
for k, v in self.query.alias_map.items()
if isinstance(v, BaseTable) and self.query.alias_refcount[k]
(
v
for k, v in self.query.alias_map.items()
if isinstance(v, BaseTable) and self.query.alias_refcount[k]
),
None,
)

@cached_property
def collection_name(self):
try:
base_table = self.base_table
except StopIteration:
# Use a dummy collection if the query doesn't specify a table
# (such as Constraint.validate() with a condition).
query = self.query_class(self)
query.aggregation_pipeline = [{"$facet": {"__null": []}}]
self.subqueries.insert(0, query)
return "__null"
return base_table.table_alias or base_table.table_name
if self.base_table:
return self.base_table.table_alias or self.base_table.table_name
# Use a dummy collection if the query doesn't specify a table
# (such as Constraint.validate() with a condition).
query = self.query_class(self)
query.aggregation_pipeline = [{"$facet": {"__null": []}}]
self.subqueries.insert(0, query)
return "__null"

@cached_property
def collection(self):
Expand Down

0 comments on commit 176cd33

Please sign in to comment.