Skip to content

Commit

Permalink
Add options hash to model.save
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko authored and bmac committed Jun 13, 2015
1 parent bfda2ea commit f536223
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions packages/ember-data/lib/system/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ var Adapter = Ember.Object.extend({
@param {DS.Store} store
@param {DS.Model} type the DS.Model class of the record
@param {DS.Snapshot} snapshot
@param {Object} options
@return {Promise} promise
*/
createRecord: null,
Expand Down Expand Up @@ -324,6 +325,7 @@ var Adapter = Ember.Object.extend({
@param {DS.Store} store
@param {DS.Model} type the DS.Model class of the record
@param {DS.Snapshot} snapshot
@param {Object} options
@return {Promise} promise
*/
updateRecord: null,
Expand Down Expand Up @@ -366,6 +368,7 @@ var Adapter = Ember.Object.extend({
@param {DS.Store} store
@param {DS.Model} type the DS.Model class of the record
@param {DS.Snapshot} snapshot
@param {Object} options
@return {Promise} promise
*/
deleteRecord: null,
Expand Down
5 changes: 3 additions & 2 deletions packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,14 @@ var Model = Ember.Object.extend(Ember.Evented, {
});
```
@method save
@param {Object} options a hash specifying save options sent to the server.
@return {Promise} a promise that will be resolved when the adapter returns
successfully or rejected if the adapter returns with an error.
*/
save: function() {
save: function(options) {
var model = this;
return PromiseObject.create({
promise: this._internalModel.save().then(function() {
promise: this._internalModel.save(options).then(function() {
return model;
})
});
Expand Down
22 changes: 14 additions & 8 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,12 +1349,17 @@ Store = Service.extend({
@private
@param {InternalModel} internalModel
@param {Resolver} resolver
@param {Object} options
*/
scheduleSave: function(internalModel, resolver) {
scheduleSave: function(internalModel, resolver, options) {
var snapshot = internalModel.createSnapshot();
internalModel.flushChangedAttributes();
internalModel.adapterWillCommit();
this._pendingSave.push([snapshot, resolver]);
this._pendingSave.push({
snapshot: snapshot,
response: resolver,
options: options
});
once(this, 'flushPendingSave');
},

Expand All @@ -1369,9 +1374,10 @@ Store = Service.extend({
var pending = this._pendingSave.slice();
this._pendingSave = [];

forEach(pending, function(tuple) {
var snapshot = tuple[0];
var resolver = tuple[1];
forEach(pending, function(pendingItem) {
var snapshot = pendingItem.snapshot;
var resolver = pendingItem.resolver;
var options = pendingItem.options;
var record = snapshot._internalModel;
var adapter = this.adapterFor(record.type.modelName);
var operation;
Expand All @@ -1386,7 +1392,7 @@ Store = Service.extend({
operation = 'updateRecord';
}

resolver.resolve(_commit(adapter, this, operation, snapshot));
resolver.resolve(_commit(adapter, this, operation, snapshot, options));
}, this);
},

Expand Down Expand Up @@ -2161,11 +2167,11 @@ function defaultSerializer(container) {
container.lookup('serializer:-default');
}

function _commit(adapter, store, operation, snapshot) {
function _commit(adapter, store, operation, snapshot, options) {
var record = snapshot._internalModel;
var modelName = snapshot.modelName;
var type = store.modelFor(modelName);
var promise = adapter[operation](store, type, snapshot);
var promise = adapter[operation](store, type, snapshot, options); // TODO check this out
var serializer = serializerForAdapter(store, adapter, modelName);
var label = "DS: Extract and notify about " + operation + " completion of " + record;

Expand Down

0 comments on commit f536223

Please sign in to comment.