This DataMapper extension adds deep cloning functionality to your resource objects. You can use it to recursively clone objects following spefic relations which need to be specified explicitly.
Given the following models:
class Blog has n, :posts end class Post belongs_to :blog end
Cloning a blog including all its posts would look like:
new_blog = blog.deep_clone(:posts)
This would initialize a new Blog object with all attrbutes taken from the original
consist of (unsaved) clones of the original entrys from
If you don't want just to initialize the clones but to create them to, use
:create as first parameter:
new_blog = blog.deep_clone(:create, :posts)
Given a further model
class Comment belongs_to :post end Post.has n, :comments
You can also specify nested parameters like:
blog.deep_clone(:posts => :comments)
It's also possible to spcify Arrays of relation names.