lundi 28 août 2017

Ember Data lazy load hasMany relationships without relationship ids

Is it possible to lazy load relationships without having the Ids of the relationship.( for both the JSON:API and REST serializer/adapter)

Currently given the model

// BaseModel
export default DS.Model.extend({
  related_model                   : DS.hasMany('related_model', {async:true}),
});

if the API responds with something like

{
  related_model_ids : [1,2,3]
}

then ember data with load fk models lazily.

/related_model/1
/related_model/2
/related_model/3

However for the performance cost of loading a 1:* relationship in a SQL backend is pretty much the same for fetching just the IDs or the entire data for all the related records I still have to JOIN the tables. to the backend/ORM it not really lazy or sideloading as all related records still need to be fetched on the baseModel request

The reasoning for requiring the model ids in the baseModel request seems to be that without knowing the IDs it will not be possible to make the relatedModel request. However that should be not required, a find query with baseModel id on the relatedModel should work just as well.

i.e. Is there way where Ember data can instead make directly the query on the relatedModel with something like this if the relationship is async

/related_model?base_model_id=1

This way the relatedModels are only loaded/joined when called required and not with every baseModel request




Aucun commentaire:

Enregistrer un commentaire