Partial data models

Is there any “state of art” or tips & tricks for how to use ember-data and in the same time take advantage of having partial data models (having simple model for list as a part of complete model for detail).

Is the best way for this case to drop ember-data?

Do the bigger companies using their own private solutions?

A found https://github.com/BookingSync/ember-data-partial-model, but last commit is form 2016.

My preference is to be explicit about it and have two models, with a relationship between them if you need to use the simpler one to load the full one.

Like PostSummary vs Post, or Post vs PostDetail.

2 Likes

To clarify, this doesn’t necessarily mean duplicating fields in two models.

You can have all the basic fields in Post and only the extended fields in PostDetail. When you want all of them, you load the Post while including (in the sense of JSON:API included) PostDetail.

Thank you for your opinion. And when you create or update, do you update two separete models with two endpoints, or another model like PostForm and let backend handle processing?

It depends on how badly you need atomic updates. If it’s not a big deal, updating the two models separately works fine. And it has the benefit of being explicit from ember-data’s perspective.

If you do need atomic updates, then you do want a smarter endpoint on the server that can take the whole update at once. If you do that, you need to make sure the response that comes back updates both models ember data’s cache (if the response uses JSON:API includedwith both the real models that should do it).

One of the motivations behind ember-m3 which is alternative model layer for ember-data is support for partial data models.

Thanks for tip @runspired!