0

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
""""

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.