Sha256: 6637e2c05dad37535cce09f6ad3d48498bb077674f47b025dd1c9030962731d4
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
# Datamapper deep cloning extention This [DataMapper](http://github.com/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. ## Usage 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 `blog`. `new_blog.posts` would consist of (unsaved) clones of the original entrys from `blog.posts`. 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) ### Nested recursion Given a further model `Comment`: 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.
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dm-deep_cloning-1.0.3 | README.md |
dm-deep_cloning-1.0.2 | README.md |
dm-deep_cloning-1.0.1 | README.md |