Mateusz Nowak
Mateusz Nowak

Reputation: 4121

How to update links attribute in ember data dynamically?

To load async relationship ember data payload usually contains links attribute.

{
  "post": {
    "id": 1,
    "title": "Progressive Enhancement is Dead",
    "links": {
      "user": "/people/tomdale"
    },
  },
}

In my case application have to create link itself due to the fact that it operate on date and time selected by the user. Link to the relationship is not fixed. It there any way to change model link attribute on runtime or do I really need to create whole relationship manually using Ember.$.ajax?

Upvotes: 0

Views: 70

Answers (1)

andrusieczko
andrusieczko

Reputation: 2824

You can create a serializer to customize the links field. Example:

App.PostSerializer = DS.RESTSerializer.extend({
    normalizePayload: function(payload) {
      payload.links = {
        "user": getMyLink(payload.links, payload.id)
      };
      return payload;
    }
});

where getMyLink is your custom function.

Does this address your problem?

Upvotes: 1

Related Questions