# Making a copy of a model and all its associated records

**URL:** <https://www.ruby-forum.com/t/making-a-copy-of-a-model-and-all-its-associated-records/141725>\
**Category:** Rails\
**Created:** [June 30, 2008, 6:32am UTC](https://www.ruby-forum.com/t/making-a-copy-of-a-model-and-all-its-associated-records/141725 "2008-06-30T06:32:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [June 30, 2008, 6:32am UTC](https://www.ruby-forum.com/t/making-a-copy-of-a-model-and-all-its-associated-records/141725/1 "2008-06-30T06:32:31Z")

</div>

Hi all,

I have a question regarding the duplication of a model and it’s  
associations. For example, if I have ModelA and it has\_many SubModelAs  
and has\_many SubModelBs associated with it. Each of the SubModels a  
belongs to ModelA. Is there a quick way of copying ModelA and the  
structure that lays below it? In the end I’ll then end up with ModelB  
which is a copy of A, and it has copies of SubModelA and SubModelB  
records.

Cheers,  
Diego
