Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (29 sloc) 0.802 kb
  • Merges associations/attributes you want
  • Can merge duplicates
  • Protects from self-merges
  • Keeps counters valid
  • Removes merged record

INSTALL

Rails plugin

rails plugin install git://github.com/grosser/ar_merge.git

OR Gem

gem install ar_merge

USAGE

Merge from outside the model:

user.merge!(other,:attributes=>user.attributes.keys,:associations=>%w[movies friends])`

Merge from inside the model

User < ActiveRecord::Base
  def merge!(other)
    super(other,:attributes=>%w[email website])
  end
end

Merge duplicates

#merge all new users, that have the same email
User.merge_duplicates!(User.find_all_by_status('new')) , :compare=>:email)

AUTHOR

Michael Grosser
michael@grosser.it
License: MIT

Jump to Line
Something went wrong with that request. Please try again.