ActiveMerge
<img src=“https://badge.fury.io/rb/active_merge.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/nepalez/active_merge.svg” alt=“Build Status” /> <img src=“https://codeclimate.com/github/nepalez/active_merge.png” /> <img src=“https://gemnasium.com/nepalez/active_merge.svg” alt=“Dependency Status” /> <img src=“https://coveralls.io/repos/nepalez/active_merge/badge.png” alt=“Coverage Status” />
Declares the ActiveMerge
module for extending ActiveRecord models.
The module contains the merge_all
class method for merging class instances into the first one.
When merging a list of instances:
-
all “has_many” relatives are reattached to the instance with the lowest id
-
all the instances except for the first one (with the lowest id) are deleted
Example
class Post < ActiveRecord
extend ActiveMerge
has_many :comments
end
Post.all.merge_all
# This will merge all the posts into the first one.
# The other posts will be deleted after their comment are reattached
# to the first post.
License
This project rocks and uses MIT-LICENSE.