# Is there a suggested approach to generate a relationship link?

**URL:** https://discuss.emberjs.com/t/is-there-a-suggested-approach-to-generate-a-relationship-link/16996
**Category:** Ember Data
**Created:** [August 26, 2019, 2:36am UTC](https://discuss.emberjs.com/t/is-there-a-suggested-approach-to-generate-a-relationship-link/16996 "2019-08-26T02:36:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Garrick](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/garrick/32/12156_2.png) [@Garrick](https://discuss.emberjs.com/u/Garrick)
#### Post date: [August 26, 2019, 2:36am UTC](https://discuss.emberjs.com/t/is-there-a-suggested-approach-to-generate-a-relationship-link/16996/1 "2019-08-26T02:36:48Z")

</div>

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](https://davidtang.io/2016/02/21/handling-nested-resources-in-ember-data.html) and [Customizing Relationship Links with JSON API - Ember Igniter](https://emberigniter.com/custom-relationship-links-json-api/) 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`)

```auto
{
    "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`)

```auto
{
    "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
            }
        }
    ]
}

```

---

<div class="post-metadata">

### Author: ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)
#### Post date: [August 26, 2019, 7:09pm UTC](https://discuss.emberjs.com/t/is-there-a-suggested-approach-to-generate-a-relationship-link/16996/2 "2019-08-26T19:09:55Z")

</div>

Everything I’ve ever seen had it in the serializer, and I think that makes sense. In a way you’re saying “here’s a record from the backend, it doesn’t look exactly how i’d like it to, so I’m supplementing and/or transforming it”. That is the job of the serializer. You’re right that the adapter usually creates request URLs but those are generally derived from business logic whereas these relationship links are actually part of the data itself (which is more the concern of the serializer layer).

---

<div class="post-metadata">

### Author: ![Garrick](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/garrick/32/12156_2.png) [@Garrick](https://discuss.emberjs.com/u/Garrick)
#### Post date: [August 26, 2019, 8:28pm UTC](https://discuss.emberjs.com/t/is-there-a-suggested-approach-to-generate-a-relationship-link/16996/3 "2019-08-26T20:28:34Z")

</div>

So you’re saying that what you’ve seen is that links have been in the serializer because it’s the serializers responsibility to shape the data to be consumed by the application?

If so I agree with you there. I just want to prevent hardcoding the path. I wonder if I can use a combination of the adapter methods in the serializer to generate the path…
