Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Links Relationships not lazy loaded? #1254

Closed
JaredSartin opened this Issue Sep 9, 2013 · 13 comments

Comments

Projects
None yet
4 participants

I have an article model in Ember/EmberData that hasMany related article, which in turn are article models.

App.Article = DS.Model.extend
  title: DS.attr 'string'
  url: DS.attr 'string'
  user: DS.belongsTo('user')
  collection: DS.belongsTo('collection')
  related_articles: DS.hasMany('article', async: true)

My server was serializing out the related articles as an array of IDs, but we wanted to move all hasMany relationships to use the links attribute and build an endpoint to pull the data from. When the related articles come out as IDs they are only loaded to the first level, which is all we need. When the related articles come through as the links association with the URL endpoint, EmberData decides to find all related articles for each child, their children, and so on until all articles in the relational tree are loaded.

We are displaying one article, with its associated related articles. At the point of display, we don't care about any related articles of the children, so no need to load them now. Is this intentional, skipping lazy load, or is this a bug?

Owner

wycats commented Sep 12, 2013

It should be relatedArticles.

What exactly is triggering the fetch?

I am unsure where the fetch is being triggered... Is there some magical logging hidden somewhere that can help? ;)

I will give it a look this morning and see if I can pinpoint it.

Also, what needs to be relatedArticles? the attribute or the hasMany?

Owner

wycats commented Sep 13, 2013

App.Article = DS.Model.extend
  title: DS.attr 'string'
  url: DS.attr 'string'
  user: DS.belongsTo('user')
  collection: DS.belongsTo('collection')
  relatedArticles: DS.hasMany('article', async: true)

Hi @wycats it would be nice if we can have the ability to customize the key names of the links. Right now, it is directly using the relationship name to get the url from the links.

Owner

wycats commented Sep 27, 2013

@kdemanawa the idea is that you can implement normalize and rename anything you need to rename.

Owner

wycats commented Sep 28, 2013

@JaredSartin I can't identify what might be causing this by reviewing the Ember Data code, so I'm closing this. However, please comment here with more information on what code path is triggering the fetch if you can identify it.

@wycats wycats closed this Sep 28, 2013

Thanks. I will be back in that portion of code soon. If this problem is
still there, I will alert you.

On Friday, September 27, 2013, Yehuda Katz wrote:

@JaredSartin https://github.com/JaredSartin I can't identify what might
be causing this by reviewing the Ember Data code, so I'm closing this.
However, please comment here with more information on what code path is
triggering the fetch if you can identify it.


Reply to this email directly or view it on GitHubhttps://github.com/emberjs/data/issues/1254#issuecomment-25288703
.

@wycats thanks!!

I have ember and ember data updated and am still running into this problem... I will try to get some information about it. Unfortunately this doesn't help:

App = Ember.Application.create({
    LOG_TRANSITIONS: true,
    LOG_TRANSITIONS_INTERNAL: true,
    LOG_BINDINGS: true,
    LOG_ACTIVE_GENERATION: true,
    LOG_VIEW_LOOKUPS: true,
});

catkins commented Apr 30, 2014

@wycats I'm running into the exact same problem.

App.Score = DS.Model.extend
  percentage: DS.attr 'number'
  owner: DS.belongsTo 'scoreOwner', polymorphic: true
  subject: DS.belongsTo 'scoreSubject', polymorphic: true
  history: DS.hasMany 'score', async: true
  subjectType: DS.attr 'string'
  calculatedAt: DS.attr 'date'

  formattedPercentage: (->
    Math.round(@get('percentage')) + '%'
  ).property('percentage').cacheable()

I'm running recent versions of Ember Data

DEBUG: Ember      : 1.5.1+pre.ff8c6bbb ember.js?body=1:3524
DEBUG: Ember Data : 1.0.0-beta.7+canary.d5562867 ember.js?body=1:3524
DEBUG: Handlebars : 1.1.1 ember.js?body=1:3524
DEBUG: jQuery     : 2.1.0 ember.js?body=1:3524

Also using the ActiveModelSerializer with pretty minimal modifications. I'll keep digging through the call stack to try and figure out why it keeps going.

catkins commented Apr 30, 2014

I'm not sure if this helps, but I put a breakpoint in the findHasMany method on the DS.RESTSerializer, and hit console.trace() for each one. I'm not sure if this helps, but the subsequent calls had much bigger stack traces.

Here's a gist of the output.

catkins commented Apr 30, 2014

@JaredSartin Did you end up finding a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment