dimagi / django-cte

Common Table Expressions (CTE) for Django
Other
334 stars 46 forks source link

WIP: Using 'real' joins instead of extra_tables and filters. #1

Closed pwfff closed 6 years ago

pwfff commented 6 years ago

My use case requires an outer join, which isn't possible with the current methods.

This PR is more to open a discussion. I've found at least one bug with my approach, and I did this with less of an understanding of the Query object, and more shotgun debugging.

My main problem right now is that some of the table names aren't properly mapped to aliases. I'll try to generate a minimal test case that triggers it once I track down why it's happening.

millerdev commented 6 years ago

@pwfff thanks taking a shot at this. I had briefly looked into doing conventional joins, but it seemed it would open a whole new can of worms. Django's Query class does a lot of magic when it constructs joins as the query is mutated, and I think at this point there is not good support for customizing them. More on that in this SO answer. Changing the join capabilities of the Query class seemed out of scope for what I was attempting with django-cte.

Having said that, I think this is really important and would love to see better support for customizing joins added to Django.

millerdev commented 6 years ago

django-cte uses real joins as of v1.0.0