12

And what are the ramifications of each?

I see that Model.save(), for example, automatically refreshes the Model with results from the server. I'm not sure if sync() does.

George Kagan
  • 5,913
  • 8
  • 46
  • 50
Paul
  • 9,285
  • 6
  • 29
  • 37

1 Answers1

19

automatically refreshes the Model with results from the server

Store.sync() refreshes modified records as well (provided you have setup the server response correctly).

So, technically, both methods do the same. However, in my opinion, you can use Model.save() only in one case: when you don't have store. Why? Because when you have store and nevertheless you use Model.save() that's mean that you have setup connection (proxy) configuration for both store and model. And that's mean that you have duplicated code which is potentially harder to maintain.

So, to summarize, you use Model.save() only if you use standalone model, without store (it may be the case when you have form which is not connected to any grid. So you create standalone model for such form), and you use Store.sync() in other cases.

Molecular Man
  • 22,277
  • 3
  • 72
  • 89
  • What response does Store.sync() expects as successful and what as error prone? – Umair A. Sep 19 '12 at 09:49
  • 1
    @UmairAshraf, it expects list of modified records in the same format as reader would expect. Also response may contain `success: true` and `message`. Take a look at requests-responses at [this example](http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/writer/writer.html) – Molecular Man Sep 19 '12 at 12:17
  • 2
    You also could have a proxy defined on model which would eliminate the duplicate code, right? – stambikk Apr 23 '15 at 07:10