Reputation: 377
I need to check if an async relationship has been loaded without triggering the load, is this possible?
Upvotes: 10
Views: 2587
Reputation: 9537
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;
Upvotes: 7
Reputation: 420
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')) {...}
Upvotes: 5
Reputation: 509
For a hasMany
relationship the non-public API for accessing this in Ember Data 1.0.0-beta.12 is model._relationships.tasks.manyArray.get('isLoaded')
Upvotes: 0
Reputation: 758
update. Still not in public API =(
For now I use this:
s._data.yourRelationshipName.get('isLoaded')
Upvotes: 1
Reputation: 2796
I'm adding this cause model._relationships.yourRelationshipName
didn't work for me
model._data.yourRelationshipName
did work tho will also be null if not loaded, and populated if it has at least started loading
Upvotes: 0
Reputation: 47367
There is no official way to accomplish this yet, but unofficially you can do
// this will be null if not loaded, and populated if it has at least started loading
if(model._relationships.yourRelationshipName) {...}
Upvotes: 3