Using the solution with "annotate" produced a query with two subqueries
(three total queries); using extra we achieved an equivalent query using
joins (one total query.)
----
SQL from query with "annotate":
{{{
SELECT [all fields from model_a],
(SELECT model_c.target_field FROM model_c JOIN model_b ON model_c.id =
model_b.c_id WHERE model_b.a_id = model_a.id) AS "target_field"
FROM "model_a"
WHERE (SELECT model_c.target_field FROM model_b JOIN model_c ON model_c.id
= model_b.c_id WHERE model_b.a_id = model_a.id)::text = 'some string')
}}}
----
SQL from query with "extra":
{{{
SELECT [all fields from model_a]
FROM "model_a" , "model_b" , "model_c"
WHERE (model_c.id = model_b.c_id AND model_b.a_id = model_a.id AND
model_c.target_field = 'some string'))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33999>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.