Ember.js: Reloading a .hasMany relationship given through "links" in payload
DS.Model.reopen({ reloadLink: function (linkKey) { if ($.isArray(linkKey)) { var promises = []; for (var i = 0; i < linkKey.length; i++) { promises.push(this.reloadLink(linkKey[i])); } return Em.RSVP.all(promises); } else { var rel = this._relationships[linkKey]; if (rel) { if (rel.reload) { return rel.reload(); } else if (rel.fetchLink) { return rel.fetchLink(); } } } }});
Example:
model: function () { var model = this.modelFor('_some_model_'); return model.reloadLink(['link1', 'link2']).then(function () { return model; });}
So there is an issue on GitHub that is not closed yet (As of today): https://github.com/emberjs/data/issues/1913
I do not know how to make it reload, but I thought that I will share the workaround that I did to resolve this issue.
I am using websockets, so when ever a new post is being created, I just send it through websocket and use the data to update the collection.
I am aware that this does not fix the issue with Ember Reload, but I guess this is a decent solution to the people who are already using Websockets / Socket.io.