Hi guys,
As you can see at those links:
-
Ember.js Clone an existing record into the store - Stack Overflow
-
hxxp://stackoverflow.com/questions/20007049/how-can-i-clone-an-ember-data-record-including-relationships
-
hxxp://stackoverflow.com/questions/14912425/ember-clone-model-for-new-record
As you can see all those questions are not answered. There is still need for documentation of code examples for copying/cloning an object in Ember Data.
What I still have so far is the following which does cloning of all attributes except hasMany items. And the drawback is that belongsTo items have to be done by hand.
var myItem= this.get('model').toJSON(),
self = this;
// todo implement getting hasMany items
// set belongsTo items by hand
myItem['someAttr'] = this.get('someAttr');
myItem['someAttr1'] = this.get('someAttr1');
myItem['someAttr2'] = this.get('someAttr2');
var duplicatedItem= this.store.createRecord('item', myItem);
So there are some points to improve:
- Saving of belongsTo not by hand
- Saving of hasMany items
A little new bump to get attention…