Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember-data: How to tell if a model's async: true relationship is loaded without triggering a load?

I need to check if an async relationship has been loaded without triggering the load, is this possible?

like image 968
Rhinon Avatar asked Mar 12 '14 23:03

Rhinon


2 Answers

After time has passed, Ember Data 2.5 got released. One of implemented features is the ds-references feature.

The references API allows to interact with your relationships. With it, it is possible to check if your RelationshipName is already loaded, without triggering a request:

model.hasMany('yourRelationshipName').value() !== null;
like image 83
Jacob van Lingen Avatar answered Nov 20 '22 02:11

Jacob van Lingen


With ember-data 1.13, the following will work for a hasMany relationship. Still a hack, but there does not seem to be a public API.

var relationships = model._internalModel._relationships.initializedRelationships;

if (relationships.yourRelationshipName.manyArray.get('isLoaded')) {...}
like image 5
Michael Edgar Avatar answered Nov 20 '22 03:11

Michael Edgar