Skip to content
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

auto-generate link objects for non-sideloaded relations #36

Merged
merged 2 commits into from
Aug 17, 2015

Conversation

ryochiji
Copy link
Contributor

Automatically generate links for non-sideloaded relations. By default, links point to the new relation endpoints, but can be overridden by setting a link attribute on DynamicRelationField (which can be a string or function which returns a URL).

@@ -242,6 +269,12 @@ def to_representation(self, instance):
WithDynamicSerializerMixin,
self).to_representation(instance)

if getattr(settings, 'DYNAMIC_REST', {}).get('ENABLE_LINKS', True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean sideloaded records will also have link fields for their relationships?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_link_fields() above will return a list that excludes sideloaded fields (see here).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that makes sense. I was wondering if a sideloaded record with a relationship that is not itself sideload would also include links, e.g:

GET /users/?include[]=location.

{
   "user": {
      "location": 1,
   },
   "locations": [{
       "id": 1,
       "links": {
           "cats": "/locations/1/cats"
       }
   }]
}

This seems like useful behavior, and I suppose Ember Data does the link extraction at the record/serializer level rather than the response/views level (not really sure though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, links will be added to any object that gets serialized by a DREST serializer, whether it's at the top level, sideloaded, or embedded.

image

@aleontiev
Copy link
Collaborator

+1, minor comment

ryochiji added a commit that referenced this pull request Aug 17, 2015
auto-generate link objects for non-sideloaded relations
@ryochiji ryochiji merged commit 4b53b54 into master Aug 17, 2015
@atzannes atzannes deleted the feature/auto-link-objects branch August 24, 2018 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants