I tried to describe my case with custom joins in django issue tracker.
I hope that I described it quite clearly. And that was helpful.
I would especially like to note that 
https://stackoverflow.com/questions/22902263/django-orm-joining-subquery/42816689#42816689
 
this solution completely suited me.

среда, 28 марта 2018 г., 10:54:06 UTC+3 пользователь Josh Smeaton написал:
>
> Someone has again brought up the lack of custom join support in django - 
> specifically LEFT OUTER joins: https://code.djangoproject.com/ticket/29262
>
> I figure it's probably something that we'd like the ORM to support but I 
> don't think we've ever really landed on a design that's palatable. I'd like 
> to try and get a rough consensus for a design and flesh out any likely 
> issues. We can then either provide a ready to go syntax that someone could 
> implement, or I could put together a DEP. At a minimum, we can point future 
> askers towards a design and "PR Welcome" them. Best case someone (possibly 
> myself) runs with the design and provides an implementation.
>
> What I'm interested in seeing are specific use cases for customising joins 
> as that will drive any kind of design.
>
> I've been playing around with some syntaxes, and this is the kind of thing 
> I'm currently leaning toward:
>
> qs = Book.objects.annotate(
> my_reviews=joins.Left(
> Review.objects.filter(user=u1),
> book=OuterRef('pk')
> )
> )
>
> This supports customising both the join type, and the join conditions (ON 
> book.id = review.book_id). One concern with this design is that now the 
> result set contains multivalues - where a book might be repeated if the 
> number of reviews that match the filter is greater than 1. We could ask the 
> user to specify whether the result is potentially multi-valued and convert 
> the result into a list, but that would require ordering and comparing the 
> current row to the previous row to check if it's a multivalue. These are 
> the kind of issues I want to flesh out, and that's only going to be 
> possible given a sufficient corpus of examples.
>
> So I'll kick off with an example that seems to be rather common:
>
> *- Add filtered results from a reverse relation / m2m relation to the 
> result set without eliminating results using a LEFT JOIN.*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1a556e51-f257-4d7f-b174-06d9fa66a721%40googlegroups.com.

Reply via email to