Created
January 11, 2013 16:57
-
-
Save kylenathan/4512271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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