1
votes

In the topics.index, I send list of topics as JSON without sending relationship ids (A topic has many posts, many users, edits, likes, etc etc which I do not show in the topics.index hence I do not want to render all the relationship ids when visiting topics.index using App.Topic.find())

So whenever a topic link is clicked, ember-data does not fetch from topic/:topic_id if it finds that the specific topic is already loaded (but this time, all the relationships are necessary). Is there a way we can force ember-data to reload every time when we go to a new link, irrespective of whether the data is already loaded or not?

Reloading also reduces number of requests made to the server.

Let's say A topic has many posts and many comments: When rendering list of topics we store post_ids and comment_ids in each of the topic, when rendering a topic,ember-data will now make two requests to the server. One to fetch all the posts with the post_ids and all the comments.

If we force to reload, we can sideload all the relationship data with one request instead of many to fetch the hasMany or belongsTo data.

1

1 Answers

1
votes

Ember Data currently lazy loads associations. So you should be able to send all the ids in your initial json.

When clicking on a specific topic, you can request the record again (using store.reloadRecord) and sideload all the models that you need, or simply let Ember Data requests them if they are used.