Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Loading relationship data of a model from secondary API request without recreating objects if already exist

$
0
0

Im trying to load comment list which may haves children comments as well. Comment model may have reference for parent comment or its children comment list if any. As the requirement I should load all comments (parent and children) from multiple comment threads into single list using first API call. In that stage there is only comments list but no any parent child relationship between comments. If user click on comment respective comment thread should be loaded. For that parent and children request are send from the model, those secondary api calls will retrieve the relevant parent or children data.

export default CommentModel.extend(ModelLikeableMixin, {
  parent: computed(function() {
    return get(this, 'store').queryRecord('comment', {
      _overrideURL: `comments/${get(this, 'id')}/parent`,
    });
  }),

  children: computed(function() {
    return get(this, 'store').query('comment', {
      _overrideURL: `comments/${get(this, 'id')}/children`,
    });
  }),
...

The issue is when retrieving child comments data from secondary request, that caused to reload already existing comments object again, and comment components of the comment list.

I want to know is there any way in the ember data to update links of model relationships if required object are already exists in the store, without recreating/reloading same object.

Here is my Stackoverflow issue.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles