django-modeltrans icon indicating copy to clipboard operation
django-modeltrans copied to clipboard

Duplicated LEFT OUTER JOIN with two related lookups on translated fields

Open jieter opened this issue 6 years ago • 0 comments

@pjburon This clearly is a different issue, so created a new one. originally reported in #34

This Queryset

Blog.objects.filter(
       Q(category__slug_i18n=slug) | Q(category__parent__slug_i18n=slug),
       is_active=active
)

Results for language = en in:

result: <MultilingualQuerySet [<Blog: Duck>, <Blog: Falcon>]>
SELECT ...
FROM "app_blog"
INNER JOIN "app_category" ON ("app_blog"."category_id" = "app_category"."id")
LEFT OUTER JOIN "app_category" T3 ON ("app_category"."parent_id" = T3."id")
WHERE (("app_category"."slug" = 'birds'
        OR T3."slug" = 'birds')
       AND "app_blog"."is_active" = true)

and for language = en in:

result: <MultilingualQuerySet []>
SELECT ..., "app_blog"."i18n", COALESCE((T3."i18n" ->> 'slug_nl'), T3."slug") AS "slug_i18n_annotation"
FROM "app_blog"
LEFT OUTER JOIN "app_category" ON ("app_blog"."category_id" = "app_category"."id")
LEFT OUTER JOIN "app_category" T3 ON ("app_category"."parent_id" = T3."id")
WHERE ((COALESCE((T3."i18n" ->> 'slug_nl'), T3."slug") = 'birds'
        OR COALESCE((T3."i18n" ->> 'slug_nl'), T3."slug") = 'birds')
       AND "app_blog"."is_active" = true)

So the problem is the duplicated LEFT OUTER JOIN.

jieter avatar Mar 14 '18 12:03 jieter