View Full Version : Dynamic Model's Best Practices

25 Jan 2014, 9:36 AM
My application is all about creating and manipulating models that the client can't know about until run-time. The approach I've been using has been to send metadata to the client along with the response payload....and then using the metachange event to set the fields on the store in question.

However, this has two problems:

1) Setting the fields of a store comes with a warning that this is an old approach (from 3.x) and should be avoided. There is also a comment to this effect in the sources for AbstractStore.

2) Without a model, I can't setup any validators.

3) I need to use a custom idProperty for my stores and I've run into an issue with this (which I documented here (http://www.sencha.com/forum/showthread.php?280160-model.getId()-with-custom-IdProperty-fails-when-store.fields-set-via-metaData).

I am guessing issues like #2 and #3 this are why simply setting fields on a store is not recommended. That is, Model != fields.

So now I am ready to refactor my code to handle dynamic models the "right way" (whatever that is).

I know how to define a model on-the-fly (http://www.sencha.com/forum/showthread.php?136362-Extjs-4-Dynamic-Model&p=624792&viewfull=1#post624792) so that part is not a problem.

However herein lies a catch 22. I don't know the model before my response arrives and I cannot get my response unless I have a store (with proxy/reader) configured -- and there does not seem to be any way to change the model of an existing store!

Whats the best way to do this?? I can, but would prefer not to break my REST API into two calls -- first to get the model definition, and second to get the model data.

In my opinion, the best way to do this would be to create the full-on (dynamic) model from within the reader, stuff it into the "metaData" and have a store detect the new model coming in from the metaData and begin to use it before loading the records.

28 Jan 2014, 6:01 AM