How can I build deep relationships with my serializer
zubeirom opened this issue · comments
Zubeir Mohamed commented
Here is what I am trying to do:
return new JSONAPISerializer('post', {
id: 'fe_id',
attributes: ['channel_id', 'title', 'description', 'thumbnail_url', 'video_url', 'views', 'createdAt', 'channel', 'upvotes', 'comments'],
channel: {
ref: 'id',
attributes: ['channelname', 'firstname', 'lastname', 'biography', 'image_url']
},
upvotes: {
ref: 'id',
attributes: ['post_id', 'channel_id']
},
comments: {
ref: 'id',
attributes: ['post_id', 'channel_id', 'comment', 'channel'],
channel: {
ref: 'id',
attributes: ['channelname', 'firstname', 'lastname', 'biography', 'image_url']
}
}
}).serialize(data);
So basically putting a relationship within a relationship. It does not work, the response does not contain the data. What can I do, and is it possible ?
Michael Milton commented
I believe it should be possible. Check out the test for it here:
jsonapi-serializer/test/serializer.js
Lines 880 to 932 in 65e483a
I can't see anything you're doing wrong in your code though, perhaps post the data you're trying to serialize as well?