You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment there doesn't seem to be a way of determining if a relationship on a model has already been loaded. For example there is no way to tell if this:
Will always return an array, regardless of if the relation has been loaded already. The same applies to hasOne/belongsTo. This forces you to re-fetch relations that are empty as you don't know if they have already been fetched.
If there a way of finding out if a relation is already loaded, or possibly (and I know this may be breaking) make findRelatedRecords/findRelatedRecord return undefined if there is no relation?
The text was updated successfully, but these errors were encountered:
There are a few alternative ways to check the contents of the cache, but also a caveat.
First, the alternatives:
// Cache#query followed by inspection of the recordconstplanet=memory.cache.query(q=>q.findRecord(ident));constmoonIds=planet?.relationships?.moons?.data;
// Cache#getRecord followed by inspection of the recordconstplanet=memory.cache.getRecord(ident);constmoonIds=planet?.relationships?.moons?.data;
The caveat is that caches by default maintain inverse relationships automatically when they are declared in a schema. Thus, fetching moons but not a planet may still assign those inverse relationships to a sparsely populated planet record in the cache. If you have no inverses on the relationship in question, then this is not a factor.
At the moment there doesn't seem to be a way of determining if a relationship on a model has already been loaded. For example there is no way to tell if this:
memory.cache.query(q => q.findRelatedRecords(ident, relationKey));
Will always return an array, regardless of if the relation has been loaded already. The same applies to hasOne/belongsTo. This forces you to re-fetch relations that are empty as you don't know if they have already been fetched.
If there a way of finding out if a relation is already loaded, or possibly (and I know this may be breaking) make findRelatedRecords/findRelatedRecord return
undefined
if there is no relation?The text was updated successfully, but these errors were encountered: