-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retrieve_related fails for toOne relationship #489
Comments
my old urls looked like this: url(r'^v1/courses/(?P<course_pk>[^/.]+)/course_terms/',
views.CourseTermViewSet.as_view({'get': 'list'}),
name='course-course_terms'),
url(r'^v1/course_terms/(?P<course_term_pk>[^/.]+)/course/',
views.CourseViewSet.as_view({'get': 'retrieve'}), # a toOne relationship
name='course_terms-course'), and here are the models:
|
Here's where it happens but not sure what the fix is:
|
This works around the problem: class RRF(ResourceRelatedField):
def use_pk_only_optimization(self):
return False |
Looks like this commit: b4dffb8 in #374 @santiavenda2 perhaps you can take a look.
|
@n2ygk Hi, can you show how the fields are declared on your |
@Anton-Shutik It's here: django-rest-framework-json-api/example/serializers.py Lines 333 to 362 in f02c7c4
|
@Anton-Shutik and see also here for the test case: django-rest-framework-json-api/example/tests/test_views.py Lines 330 to 355 in f02c7c4
|
…`retrieve_related` of a to-one relationship
@Anton-Shutik Using your new #451 support for related links, using
{'get': 'retrieve_related'}
works fine for a serializerResourceRelatedField
wheremany=True
but fails for a toOne relationship wheremany=False
.Using the old style, I had to override
get_queryset()
formany=True
views andget_object()
formany=False
views so I expect there is a similar need for another "flavor" ofretrieve_related
for toOne relationships. Does this make sense?Here's my old view code for reference:
The new code (eliminates those overrides, sets the kwarg to
pk
and updates therelated_link_view_name
s tocourse-related
andcourse_term-related
, respectively and throws this error when retrieved:The text was updated successfully, but these errors were encountered: