Open caseyprovost opened 6 years ago
First, class_name: 'User'
has no effect.
Not sure why the included
section is left out though.
@caseyprovost I'm using included
and fields
and somehow every inner relationships
key is missing đŸ¤” . Did you found anything?
@caseyprovost could you share your pagination_links
implementation please? Trying to add pagination but I don't find any docs.
@dduqueti Check out these gists:
@dduqueti Join the slack channel and DM me :) I can help you through this.
@dduqueti Hi, I encountered same issue, For example Category
has_many SubCategories
.
categories = Category.includes(:sub_categories).all # this is the problem line
render jsonapi: categories, include: [:sub_categories]
The result of jsonapi does not have included
data
*Expected Result
"data": [
Category1
Category2
Category3
],
"included": [
SubCategory1-1
]
*Real Result (SubCategory1-1 is not be included in Category1)
"data": [
Category1
Category2
Category3
SubCategory1-1
]
*Solution
# only render the parent Category
categories = Category.includes(:sub_categories).all.where(parent_id: nil)
render jsonapi: categories, include: [:sub_categories]
*Why not included ? https://jsonapi.org/format/#document-compound-documents
compound document MUST NOT include more than one resource object for each type and id pair.
In my example SubCategory is already appeared in the data
, so not appeared in included
to avoid duplicate.
Working through implementing includes I have discovered what appears to be a bug. All my other code like this works as expected and the only difference I can find is that the association is the same class as the requested object.
Controller
Serializer
The response looks nearly correct, except the includes are missing at the end. I have provided a sample below.