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
Uh oh!
There was an error while loading. Please reload this page.
-
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 userHowever,
If
field3is 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