Skip to content

Instantly share code, notes, and snippets.

@kylenathan
Created January 11, 2013 16:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylenathan/4512271 to your computer and use it in GitHub Desktop.
Save kylenathan/4512271 to your computer and use it in GitHub Desktop.
App.CreateUserRoute = Em.Route.extend({
transaction: null,
model: function() {
this.transaction = App.store.transaction();
return this.transaction.createRecord(App.User);
},
events: {
submit: function(user) {
var errors = {};
if (Em.isEmpty(user.get('name')))
errors.name = "Name is required";
if (!$.isEmptyObject(errors)) {
user.set('errors', errors);
user.set('isValid', false);
return;
}
var self = this;
user.one('didCreate', function() {
this.transitionTo('user', user);
});
this.transaction.commit();
}
},
exit: function() {
this.transaction.rollback();
}
});
@stefek99
Copy link

For anyone coming from StackOverflow / other sources... Transactions are no more.

See: https://github.com/emberjs/data/blob/master/TRANSITION.md#transaction-is-gone-save-individual-records

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment