View Full Version : Model not mapped correctly to wire when saving to remote resource

24 Oct 2011, 5:22 AM
Using Sencha Touch's data classes, I have set up a Model and a Store. I have retrieved a collection into the store from a REST service. Next thing I want to do is sync changes back to the service, but the Sencha Touch Writer class and Field class don't seem to support this very well. For example, given the following model:

Ext.regModel('News', {
fields: [
{name: 'id', type: 'int'},
{name: 'newsId', mapping: 'iid', type: 'string'},
{name: 'source', mapping: 'source', type:'string'},
{name: 'title', mapping: 'stitle', type: 'string'},
{name: 'dateModified', mapping: 'tmodified', type: 'date', convert: toDateFromJSON}

When I sync the store to the service, I get something like this on the wire (using json writer):

{"d.results": [
"title":"People will do as they are told by someone who outranks them, but...",
"dateModified": "2010-09-28T12:28:38.323Z"

The service doesn't know anything about "newsId", "source", etc.; so it will fail to accept the request. Notice when I defined my model I mapped the service field names to model field names (e.g. "iid" gets mapped to "newsId").

So I went looking for a way to tell the writer to use the mapped names. Nothing. And I went looking for a way to indicate which fields on my model should be excluded from being persisted. Nothing.

BUT... Interestingly, ExtJS 4's data package does support these concepts. So I know I'm not crazy and someone at Sencha knows these are important. I.e. See ExtJS Writer nameProperty (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.writer.Writer-cfg-nameProperty). And see ExtJS Field persist (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Field-cfg-persist) property.

These seem like pretty hefty pieces of missing functionality from Sencha Touch. I.e. Try to go beyond anything very simple with respect to syncing a store and you're screwed. What are my options?

ronan quillevere
31 Jul 2012, 5:21 AM
Did you find any solution to your problem ? I am facing the same issue.

31 Jul 2012, 7:51 AM
Nope. At some point I was going to look at Sencha 2's data layer and see if the support is better.

ronan quillevere
31 Jul 2012, 8:12 AM
nameProperty is working in ST 2.0.1 do not know if it will in futur versions. Anyway it is not powerfull enough for me but for your usecase it should be sufficient.

I will be overriding the
getRecordData in a new writer.