PDA

View Full Version : Disable record wrapping in RestProxy



oe.elvik
15 Mar 2011, 1:25 AM
I,ve observed that when you send a put request (updata a record) in a RestProxy, the updated record gets wrapped inside {records: [{.....}]} and sendt to url: "people/1" .

This seems to be a non standard way to wrap data. Even worse is it when I update a second record both the new and old unsynced records get transmitted to the same url: "people/1" and wrapped in same data set {records: [{.....},{.....}]}.

I would expect this wrapping when sending requests to url: "people" but not when sending to "people/[id]".
Is this a bug and is there a way to disable this wrapping for requests to "people/[id]"

evant
15 Mar 2011, 1:41 AM
In the next release if there's only 1 record it will be sent as:



{id: foo, prop1: bar}


Also batching has been disabled for the rest proxy.

_matias_
15 Mar 2011, 3:54 AM
In the next release (...)

Talking about the next developer's release, do you have an ETA? Just asking, not trying to be pushy

lylepratt
7 Jul 2011, 8:39 AM
I'm also having a big problem with this bug in Sencha Touch. Is there a timeline for a fix? Has it already been pushed to Ext.JS, but not to Sencha Touch? I'm just trying to judge if I should trudge through for a while or move to something completely different than RestProxy.

If there is an easy way to override this behavior, I'd love for someone to point me in the right direction.

Thanks!,
Lyle

lylepratt
7 Jul 2011, 9:32 AM
It looks like the RestProxy uses the "JsonWriter", which wraps requests with records[]. As a temporary solution, I created a new "writer" called "RestWriter" that just returns a dictionary.



Ext.data.RestWriter = Ext.extend(Ext.data.Writer, {
root: '',
encode: false,
writeRecords: function(request, data) {
if (this.encode === true) {
data = Ext.encode(data);
}

if(data.length > 1) {
request.jsonData = data
}
else {
request.jsonData = data[0]
}

return request;
}
});
Ext.data.WriterMgr.registerType('rest', Ext.data.RestWriter);


Then in your proxy, you need to define the type as "rest".



writer: {
type: 'rest'
},