-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update docs for JSONAPI relationship links #1935
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ class Api::V1::UserSerializer < ActiveModel::Serializer | |
end | ||
``` | ||
|
||
This will resilt in (example is in jsonapi adapter): | ||
This will result in (example is in jsonapi adapter): | ||
```json | ||
{ | ||
"data": { | ||
|
@@ -69,7 +69,7 @@ class Api::V1::UserSerializer < ActiveModel::Serializer | |
end | ||
``` | ||
|
||
This will resilt in (example is in jsonapi adapter): | ||
This will result in (example is in jsonapi adapter): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
```json | ||
{ | ||
"data": { | ||
|
@@ -104,12 +104,7 @@ class Api::V1::UserSerializer < ActiveModel::Serializer | |
|
||
has_many :microposts, serializer: Api::V1::MicropostSerializer do | ||
link(:related) { api_v1_microposts_path(user_id: object.id) } | ||
end | ||
|
||
#this is needed to avoid n+1, gem core devs are working to remove this necessity | ||
#more on: https://github.com/rails-api/active_model_serializers/issues/1325 | ||
def microposts | ||
object.microposts.loaded ? object.microposts : object.microposts.none | ||
include_data false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this specific comment, I think it is no longer needed. That said, we should probably rework this section. It's totally valid to have both Instead, I'd add a section below this (or elsewhere) on conditionally including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @richmolj I would say the opposite is more often: if you add links you probably don't include the relationship. I would suggest to merge this request and you can start a new one about conditionally adding data (probably in another section of the wiki) |
||
end | ||
end | ||
``` | ||
|
@@ -126,7 +121,6 @@ This will result in: | |
}, | ||
"relationships": { | ||
"microposts": { | ||
"data": [], | ||
"links": { | ||
"related": "/api/v1/microposts?user_id=1" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok