Skip to content

Commit b680a5a

Browse files
committedMay 17, 2019
Updated docs
1 parent 529721c commit b680a5a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎docs/usage.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,17 +823,22 @@ class QuestSerializer(serializers.ModelSerializer):
823823

824824
Be aware that using included resources without any form of prefetching **WILL HURT PERFORMANCE** as it will introduce m\*(n+1) queries.
825825

826-
A viewset helper was designed to allow for greater flexibility and it is automatically available when subclassing
826+
A viewset helper was designed to allow for greater flexibility and it is automatically available when subclassing.
827+
You can also define your custom queryset for `select` or `prefetch` related for each `include` that comes from the url.
828+
It has a priority over automatically added preloads.
827829
`rest_framework_json_api.views.ModelViewSet`:
828830
```python
829831
from rest_framework_json_api import views
830832

831833
# When MyViewSet is called with ?include=author it will dynamically prefetch author and author.bio
832834
class MyViewSet(views.ModelViewSet):
833835
queryset = Book.objects.all()
836+
select_for_includes = {
837+
'author': ['author__bio'],
838+
}
834839
prefetch_for_includes = {
835840
'__all__': [],
836-
'author': ['author', 'author__bio'],
841+
'all_authors': [Prefetch('all_authors', queryset=Author.objects.select_related('bio'))],
837842
'category.section': ['category']
838843
}
839844
```

0 commit comments

Comments
 (0)