<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - Merging Active Record models Changes</title>
  <id>tag:www.opensoul.org,2009:/2008/8/21/merging-active-record-models/changes</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  <link href="http://www.opensoul.org/2008/8/21/merging-active-record-models/changes.xml" rel="self" type="application/atom+xml"/>
  <link href="/2008/8/21/merging-active-record-models" rel="alternate" type="text/html"/>
  <updated>2008-08-21T04:15:14Z</updated>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:www.opensoul.org,2008-08-21:474:3</id>
    <published>2008-08-21T09:00:00Z</published>
    <updated>2008-08-21T04:15:14Z</updated>
    <link href="http://www.opensoul.org/2008/8/21/merging-active-record-models" rel="alternate" type="text/html"/>
    <title>Merging Active Record models</title>
<content type="html">&lt;div class=&quot;banner&quot;&gt;
&lt;img title=&quot;Merge&quot; src=&quot;/assets/2008/8/21/merge.jpg&quot; alt=&quot;Merge&quot; /&gt;
&lt;/div&gt;

	&lt;p&gt;We&#8217;ve been working on a project that involves importing a massive amount of data from multiple sources. The data is somewhat complicated, so we occasionally end up with duplicate records that need merged together. The data is highly normalized, so there are a bunch of associations that also need merged. If you&#8217;ve ever done this by hand, you know how painful it can be.&lt;/p&gt;


	&lt;p&gt;To alleviate that pain, I introduce you to &lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;merger&lt;/a&gt;, a Rails plugin for merging Active Record models.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@person.merge!(Person.find_all_by_email(@person.email))&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The plugin is pretty simple right now. All it does is:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Given a set of records, picks the oldest record (the one with the lowest id) as the one to keep&lt;/li&gt;
		&lt;li&gt;Moves any associated &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;habtm&lt;/code&gt; records from the duplicates to the record that is being kept&lt;/li&gt;
		&lt;li&gt;Deletes the duplicate records&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;We intend to add a lot to it, including:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Strategies for choosing which record to keep&lt;/li&gt;
		&lt;li&gt;Strategies for merging the individual attributes of the records&lt;/li&gt;
		&lt;li&gt;Recursively merge associations based on certain attributes&lt;/li&gt;
		&lt;li&gt;Options for what to do with the duplicate records&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;Check it out on Github&lt;/a&gt; and let us know what you think.&lt;/p&gt;


&lt;ol class=&quot;footnotes&quot;&gt;
  &lt;li&gt;Photo adapted from &lt;a href=&quot;http://flickr.com/photos/xrrr/2478140383/&quot;&gt;http://flickr.com/photos/xrrr/2478140383/&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:www.opensoul.org,2008-08-21:473:2</id>
    <published>2008-08-21T09:00:00Z</published>
    <updated>2008-08-21T04:14:53Z</updated>
    <link href="http://www.opensoul.org/2008/8/21/merging-active-record-models" rel="alternate" type="text/html"/>
    <title>Merging Active Record models</title>
<content type="html">&lt;div class=&quot;banner&quot;&gt;
&lt;img title=&quot;Merge&quot; src=&quot;/assets/2008/8/21/merge.jpg&quot; alt=&quot;Merge&quot; /&gt;
&lt;/div&gt;

	&lt;p&gt;We&#8217;ve been working on a project that involves importing a massive amount of data from multiple sources. The data is somewhat complicated, so we occasionally end up with duplicate records that need merged together. The data is highly normalized, so there are a bunch of associations that also need merged. If you&#8217;ve ever done this by hand, you know how painful it can be.&lt;/p&gt;


	&lt;p&gt;To alleviate that pain, I introduce you to &lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;merger&lt;/a&gt;, a Rails plugin for merging Active Record models.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@person.merge!(Person.find_all_by_email(@person.email))&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The plugin is pretty simple right now. All it does is:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Given a set of records, picks the oldest record (the one with the lowest id) as the one to keep&lt;/li&gt;
		&lt;li&gt;Moves any associated &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;habtm&lt;/code&gt; records from the duplicates to the record that is being kept&lt;/li&gt;
		&lt;li&gt;Deletes the duplicate records&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;We intend to add a lot to it, including:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Strategies for choosing which record to keep&lt;/li&gt;
		&lt;li&gt;Strategies for merging the individual attributes of the records&lt;/li&gt;
		&lt;li&gt;Recursively merge associations based on certain attributes&lt;/li&gt;
		&lt;li&gt;Options for what to do with the duplicate records&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;Check it out on Github&lt;/a&gt; and let us know what you think.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:www.opensoul.org,2008-08-21:472:1</id>
    <updated>2008-08-21T04:10:31Z</updated>
    <link href="http://www.opensoul.org/2009/1/7/merging-active-record-models" rel="alternate" type="text/html"/>
    <title>Merging Active Record models</title>
<content type="html">&lt;div class=&quot;banner&quot;&gt;
&lt;img title=&quot;Merge&quot; src=&quot;/assets/2008/8/21/merge.jpg&quot; alt=&quot;Merge&quot; /&gt;
&lt;/div&gt;

	&lt;p&gt;We&#8217;ve been working on a project that involves importing a massive amount of data from multiple sources. The data is somewhat complicated, so we occasionally end up with duplicate records that need merged together. The data is highly normalized, so there are a bunch of associations that also need merged. If you&#8217;ve ever done this by hand, you know how painful it can be.&lt;/p&gt;


	&lt;p&gt;To alleviate that pain, I introduce you to &lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;merger&lt;/a&gt;, a Rails plugin for merging Active Record models.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;@person.merge!(Person.find_all_by_email(@person.email))&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The plugin is pretty simple right now. All it does is:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Given a set of records, picks the oldest record (the one with the lowest id) as the one to keep&lt;/li&gt;
		&lt;li&gt;Moves any associated &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;habtm&lt;/code&gt; records from the duplicates to the record that is being kept&lt;/li&gt;
		&lt;li&gt;Deletes the duplicate records&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;We intend to add a lot to it, including:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Strategies for choosing which record to keep&lt;/li&gt;
		&lt;li&gt;Strategies for merging the individual attributes of the records&lt;/li&gt;
		&lt;li&gt;Recursively merge associations based on certain attributes&lt;/li&gt;
		&lt;li&gt;Options for what to do with the duplicate records&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;a href=&quot;http://github.com/collectiveidea/merger&quot;&gt;Check it out on Github&lt;/a&gt; and let us know what you think.&lt;/p&gt;</content>  </entry>
</feed>
