tortoise-orm
tortoise-orm copied to clipboard
Difference Between `.select_related()`, `.fetch_related()` and `.prefetch_related()`
I couldn't find the difference or the use cases for .select_related(), .fetch_related() and .prefetch_related() in the documentation. It would be really helpful to have it documented.
same question
select_related() - selects related model fields in same query, through join. Works only on FK fields, as in case of OneToMany relationship there is no good way to request it in one query
prefetch_related() - fetches related data in separate queries under the hood, but can fetch any type of relationship
fetch_related() - basically same as prefetch, but is called on already fetched model instance, not queryset