Skip to content

Commit b7f4b5e

Browse files
committed
combinator queries move and with_cte to combined query
1 parent aac7ed9 commit b7f4b5e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

django_cte/cte.py

+11
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def as_manager(cls):
153153
as_manager.queryset_only = True
154154
as_manager = classmethod(as_manager)
155155

156+
def _combinator_query(self, combinator, *other_qs, all=False):
157+
clone = super(CTEQuerySet, self)._combinator_query(combinator, *other_qs, all=False)
158+
if clone.query.combinator:
159+
# Move CTE onto parent query, we can modify as they are cloned by super
160+
sub_cte = []
161+
for query in clone.query.combined_queries:
162+
sub_cte.extend(query._with_ctes)
163+
query._with_ctes=[]
164+
clone.query._with_ctes = sub_cte
165+
return clone
166+
156167

157168
class CTEManager(Manager.from_queryset(CTEQuerySet)):
158169
"""Manager for models that perform CTE queries"""

0 commit comments

Comments
 (0)