Reputation: 524
Django ORM query
projects = Project.objects.filter(category__id=1111)
This generates following sql query, [join used]
""""
select *
FROM "project"
INNER JOIN "category" ON ( "project"."category_id" = "category"."id" )
WHERE "project"."category_id" = 1111
""""
Is it possible to avoid join and get result like this?
""""
select *
FROM "project"
WHERE "project"."category_id" = 1111
""""
Upvotes: 0
Views: 164
Reputation: 599620
The underlying db column is called category_id
(with a single underscore); you can filter on that directly:
projects = Project.objects.filter(category_id=1111)
Upvotes: 1