Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Merge 2 ActiveRecords, preserving attributes, associations and counters
Ruby
tag: v0.1.3

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
README.markdown
Rakefile
VERSION
ar_merge.gemspec
init.rb

README.markdown

  • Merges associations/attributes you want
  • Can merge duplicates
  • Protects from self-merges
  • Keeps counters valid
  • Removes merged record

INSTALL

Rails plugin

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

OR Gem

sudo 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
grosser.michael@gmail.com Hereby placed under public domain, do what you want, just do not hold me accountable...

Something went wrong with that request. Please try again.