Created
August 13, 2012 20:50
-
-
Save lukemelia/3343996 to your computer and use it in GitHub Desktop.
Batch transaction save
This file contains 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.profileEditorController = Em.ObjectController.extend({ | |
addressBinding: 'content.address' | |
}); | |
App.Router = Em.Router.extend({ | |
root: Em.Route.extend({ | |
profile: Em.Route.extend({ | |
route: 'profile', | |
edit: Em.Route.extend({ | |
route: 'edit', | |
connectOutlets: function(router) { | |
router.get('applicationController').connectOutlet('profileEditor', router.get('currentUser')); | |
}, | |
save: function(router) { | |
var transaction = router.get('store').transaction(), | |
user = router.getPath('profileEditorController.content'), | |
address = user.get('address'); | |
transaction.add(user); | |
transaction.add(address); | |
transaction.commit(); | |
transaction.then(function(){ | |
router.transitionTo('profile') | |
}, function(){ | |
// Do somphing on error | |
}); | |
// OR OTHER PROMISE API LIKE: | |
transaction.done(function(){ | |
router.transitionTo('profile') | |
}); | |
transaction.fail(function(){ | |
// Do somphing on error | |
}); | |
} | |
}) | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Luke,
I was wondering how we could add multiple association in the save function or elsewhere using router version 2. Just to continue with your code sample since the idea is thesame of adding the associated models in the save evet in the router's events hook :
This also doe not work:
Though it will save, the association are not added in the created record. What do I need to change. Thanks