vendredi 1 mai 2015

get length of hasMany relationship without triggering fetch

model:

DS.Model.extend({
  title: DS.attr('string'),
  body: DS.attr('string'),
  comments: DS.hasMany('comment', { async: true} ),

  hasComments: Ember.computed.gt('comments.length', 0)
});

payload:

{ 
  "id": "abcdefg",
  "title": "some cats are cool",
  "body": "",
  "comments: ["100", "101", "102"]
}

But the hasComments computed property triggers a fetch for each comment individually.. I don't want this :D

I know this works (avoids the fetch), but doesn't seem ideal:

hasComments: Ember.computed.gt('data.comments.length', 0)

ember.js 1.8.1

ember-data 1.0.0-beta.11

Any other recommendations on achieving a computed property based off of the length




Aucun commentaire:

Enregistrer un commentaire