What happens when some fields fetched using .only() in a queryset but more fields fetched later ? #6
acpmasquerade
started this conversation in
Django
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When .only("field1", "field2") filter is applied, only the mentioned fields are fetched in the database query.
For example, for a model User
qs = User.objects.only("name", "email")
is translated to SQL similar to
select id, name, email from user
However,
If
field3
is fetched later on, a separate query is executed to suffice the invocation.Therefore, if required to run a field inside a loop, each iteration will create a new database query.
Beta Was this translation helpful? Give feedback.
All reactions