Skip to content

Instantly share code, notes, and snippets.

@pads
Last active February 7, 2016 14:31
Show Gist options
  • Select an option

  • Save pads/5b567312d03263325de5 to your computer and use it in GitHub Desktop.

Select an option

Save pads/5b567312d03263325de5 to your computer and use it in GitHub Desktop.
Dynamically rollback Ember model relationships
App.MyModel.eachRelationship (name, relationship) ->
relationshipInstance = modelInstance.get name
if relationshipInstance
if relationship.kind is 'belongsTo'
relationshipInstance.rollback()
else if relationshipInstance.content and relationship.kind is 'hasMany'
relationshipInstance.content.forEach (record) ->
record.rollback()
@pads

pads commented Dec 12, 2014

Copy link
Copy Markdown
Author

This is not code that lends itself to testing. The eachRelationship function will trigger model fetching from the dependency injection container. There is no easy way to control this. One solution is to use the ES6 module loader to import the model class and import a different class when testing.

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