# Duplicate an object of an Ember Data model

**URL:** <https://discuss.emberjs.com/t/duplicate-an-object-of-an-ember-data-model/3584>\
**Category:** Ember Data\
**Created:** [December 12, 2013, 4:40pm UTC](https://discuss.emberjs.com/t/duplicate-an-object-of-an-ember-data-model/3584 "2013-12-12T16:40:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cannect](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@Cannect](https://discuss.emberjs.com/u/Cannect)\
**Post date:** [December 12, 2013, 4:40pm UTC](https://discuss.emberjs.com/t/duplicate-an-object-of-an-ember-data-model/3584/1 "2013-12-12T16:40:18Z")

</div>

Hi guys,

As you can see at those links:

- [How to create a duplicate of an object (obj.dup)](http://discuss.emberjs.com/t/how-to-create-a-duplicate-of-an-object-obj-dup/3259)

- [Ember.js Clone an existing record into the store - Stack Overflow](http://stackoverflow.com/questions/20477301/ember-js-clone-an-existing-record-into-the-store)

- 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:

1. Saving of belongsTo not by hand
2. Saving of hasMany items

A little new bump to get attention…

---

<div class="post-metadata">

**Author:** ![kroofy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kroofy/32/15370_2.png) [@kroofy](https://discuss.emberjs.com/u/kroofy)\
**Post date:** [December 19, 2013, 8:09pm UTC](https://discuss.emberjs.com/t/duplicate-an-object-of-an-ember-data-model/3584/2 "2013-12-19T20:09:42Z")

</div>

I was the one posting the original question at [ember.js - Ember clone model for new record - Stack Overflow](http://stackoverflow.com/questions/14912425/ember-clone-model-for-new-record)

I have updated my answer there with a method I’m currently using. Maybe there’s a better way of handling the async nature of hasMany?

At least it’s handling belongsTo dynamically.
