View Full Version : model.save() vs model.store.sync() - one works, other doesn't

1 Jun 2012, 4:13 AM
Fairly new to this, so I might be doing something stupid, but here's the gist of it:

I have a Model hooked up to a Store with a AJAX proxy using JSON.

On one of these records after updating if I try to do "rec.save()" I get a unhandled exception of "You are using a ServerProxy but have not supplied it with a url".

However, I do "rec.store.sync()" I see in Fiddler or the Chrome debugger that there is a PUT request against the URL.

Is this just erratic behavior from ExtJS' side, or am I supposed to do this differently?

Basically, this is the store:

id: 'dataSourceStore',
model: 'DataSource',
type: 'ajax',

url: '/datasources.json',

create: 'POST',
read: 'GET',
update: 'PUT',
destroy: 'DELETE'

type: 'json',
root: 'Result'

type: 'json'
autoLoad: false

(The /datasources.json endpoint is a WCF backend that can take REST requests..)

ExtJS 4.1.0

1 Jun 2012, 7:09 AM
I think the problem is the fact that the proxy is configured on the store, not on the model

try printing model.getProxy() and watch if prints something.

Otherwise, the problem may be the fact that you must submit some options to save() method: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-method-save (http://www.extjs.localhost:8080/docs/index.html#!/api/Ext.data.Model-method-save)

4 Jun 2012, 3:00 AM

Thanks - model.getProxy() does indeed return an object, however, it does not seem to be the same as rec.store.getProxy(). (the .url property is undefined/null)

However, since this model record belongs to the store, why does it have it's own proxy..? This model instance was loaded using the store and proxy in the first place.. Is this just by design?

I can of course do rec.setProxy(rec.store.getProxy()) and then do the rec.save() or rec.destroy() etc, which then generates the HTTP request, but is there some reason why I might not want to do this?

(Passing an Ext.data.Operation object to save sort of seems like overkill if I just want to save that one object using the store and proxy it was already in.. And I don't even know if it will pick up the correct proxy URL etc then - I'd probably have to supply it manually then also)

I'm just trying to avoid doing something stupid as my first move using ExtJS :)

4 Jun 2012, 3:13 AM
I don't know about this, but you can define the proxy only on the model (and not on the store) and the store will have the same proxy of the model.

Why if you set the store proxy and not the model one you obtain this result, I really don't know. Maybe a someone from sencha support can answer this.