Last active
February 7, 2016 14:31
-
-
Save pads/5b567312d03263325de5 to your computer and use it in GitHub Desktop.
Dynamically rollback Ember model relationships
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.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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not code that lends itself to testing. The
eachRelationshipfunction 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.