How to migrate dynamic Model attributes from v4.12 to v5 in emberjs

12 hours ago 1
ARTICLE AD BOX

I have a project I am preparing to migrate from ember.js 4.12 to 5.

As part of that, I am trying to fix the [early static deprecation](https://deprecations.emberjs.com/id/ember-data-deprecate-early-static/).

However, this project currently has code that transforms some existing models into new models with additional and modified attributes that depend on the original attributes. This is done in two ways:

A decorator used on a Model

Routes call a transformation function in beforeModel that makes an http request to get schema info that is merged with the original model to create a new model.

In both cases it currently needs to get the current attributes and relationships to merge the new schema information into.

While I can use the SchemaService in order to get the attributes instead of directly from the class, that ends up populating the store's cache, so that even unregistering and re-registering the model doesn't update the schema in the store.

So, what is the proper way to do something like this in ember 5 and later?

I suspect the answer has something to do with a custom SchemaDefinitionService, but I haven't been able to find any examples of how to do that, especially in a way that makes use of existing Models in addition to dynamic schemas. And that seems like a pretty substantial refactor to do.

Read Entire Article