Skip to content

Instantly share code, notes, and snippets.

@kenelliott
Created February 17, 2014 19:57
Show Gist options
  • Select an option

  • Save kenelliott/9057867 to your computer and use it in GitHub Desktop.

Select an option

Save kenelliott/9057867 to your computer and use it in GitHub Desktop.
# rollback target and related models
# http://stackoverflow.com/questions/19362584/how-to-rollback-changes-to-hasmany-in-ember-data
rollbackDirtyRecords = (context, transition) ->
relationships = Em.get(App[context.modelName.camelize().titleize()], "relationshipsByName")
content = context.get('controller.content')
transition.then ->
relationships.forEach (name, relationship) ->
relatedModel = content.get(name)
relatedModel.rollback() if relatedModel? and relatedModel.get('isDirty')
content.rollback() if content.get("isDirty")
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment