-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support JSONAPI include params with links/loading
The current implementation does support conditionally sideloading relationships based on the 'include' URL param. However, omitting the relationship still loads the relationship (to populate the type/id 'relationships' payload), somewhat defeating the purpose. Instead, this changes the flow to: 1. If the relationship is included, load it and include it the response. 2. If the relationship is not included but there is a JSONAPI link, include the link in the response but do not load the relationship or include data. 3. If the relationship is not in the URL param and there is no link, do not include this node in the 'relationships' response. The `current_include_tree` edits in json_api.rb are to pass the current nested includes. This is to support when multiple entities have the same relationship, e.g. `/blogs/?include=posts.tags,tags` should include both blog tags and post tags, but `/blogs/?include=posts.tags` should only include post tags. This API is opt-in to support users who always want to load `relationships` data. To opt-in: ```ruby class BlogSerializer < ActiveModel::Serializer associations_via_include_param(true) # opt-in to this pattern has_many :tags has_many :posts do link :self, '//example.com/blogs/relationships/posts' end end ``` JSONAPI include parameters (http://jsonapi.org/format/#fetching-includes). Fixes #1707 Fixes #1555
- Loading branch information
Lee Richmond
committed
May 28, 2016
1 parent
f48fd2a
commit b6493b2
Showing
8 changed files
with
234 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.