Q: Is there a suggested approach to generate a relationship link?
I have an article with a hasMany relationship to comments, but the article response does not contain a relationship link, so I must add a relationship link to the comments via links
property - as suggested by https://davidtang.io/2016/02/21/handling-nested-resources-in-ember-data.html and Customizing Relationship Links with JSON API - Ember Igniter articles.
While adding the link in the serializer works, the examples I’ve seen have the URLs for the link hardcoded in the serializer. Having the URLs hardcoded in the serializer seems like it could be confusing and cause possible maintenance issues since the adapter is where the URLs for models is usually created.
Is there an Ember Data recommended approach to generate links for relationships when the payload does not contain the links?
For context, below are the responses of the APIs I am working with.
Article Response - (/articles/:slug
)
{
"article":{
"title":"Pudding!",
"slug":"pudingi-7sz17d",
"body":"Hi Hello How are you!",
"createdAt":"2019-08-22T08:45:15.787Z",
"updatedAt":"2019-08-22T08:45:15.787Z",
"tagList":[],
"description":"Myself",
"author":{
"username":"Srinivasa",
"bio":null,
"image":"https://static.productionready.io/images/smiley-cyrus.jpg",
"following":false
},
"favorited":false,
"favoritesCount":2
}
}
Comments Response - (/articles/:slug/comments
)
{
"comments":[
{
"id":44616,
"createdAt":"2019-08-22T09:31:56.531Z",
"updatedAt":"2019-08-22T09:31:56.531Z",
"body":"Doing well. How are you?",
"author":{
"username":"gc-conduit",
"bio":null,
"image":"https://static.productionready.io/images/smiley-cyrus.jpg",
"following":false
}
}
]
}