angular2-jsonapi
angular2-jsonapi copied to clipboard
lazy-load relationships?
Hello!
From the documentation, it appears the relationship-loading strategy is to use include to return relationships with the primary payload. This certainly works, but can be a bit heavy.
Any thoughts on using a lazy-load approach to load relationships when needed?
Background
I've used Ember quite extensively and Ember Data in particular allows you to mark relationships as async. For example, if you have a Post model with a Comment relationship, fetching a Post would include all of the Comment ids associated with that Post, but not embed the records themselves. Then when referencing the Post's Comment in a template, it would by dynamically fetched and added to the local store.
This has some advantages in that relationships are only loaded when needed, cuts down on payload size, and allows you to potentially apply difference cache policies per model.
@HennerM do you have any thoughts on this?
Its true that this would be a nice feature to have.
In my opinion a viable approach would be to define the lazy loaded relations as Observable<T>. which gets resolved either immediately or by doing a separate request.
I am not sure yet if there are restrictions with this solution. Currently I want to fix the existing bugs and then implement a prototype for the feature, so this can get included hopefully in 4.0 or the successor 4.1.
Is this feature still being worked on? Right now I want to fetch from a belongTo relation a hashMany relation (something like teacher.schoolClass.children). I don't want to load all the children with the teacher call, so this feature would be a very nice addition to the existing code base.