Created
October 29, 2014 00:08
-
-
Save crabbits/c306e548a674a18e1e88 to your computer and use it in GitHub Desktop.
Ember data clone record
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
DS.Model.reopen | |
clone: (overrides) -> | |
model = this | |
attrs = model.toJSON() | |
klass = model.constructor | |
root = Em.String.decamelize(klass.toString().split(".")[1]) | |
@eachRelationship (key, relationship) -> | |
if relationship.kind is "belongsTo" | |
attrs[key] = model.get(key) | |
return | |
delete attrs.id | |
Em.setProperties attrs, overrides if Em.typeOf(overrides) is "object" | |
@store.createRecord root, attrs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment