Forum: Ruby on Rails how do i merge records together

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tim D. (Guest)
on 2009-01-16 21:43
Hi I am Tim Dunn and am working on a web app to help people research
their family history. I am wondering how to merge records from the same
table into one record based on if they are exact or partial matches in
any given set of fields.
for example:

Record 1:
Name:John S.
source 1 for name: Minnesota Death Records
listed as in source 1 for Name: John S.
listed column in source 1 for Name:Husband
determined logic in source 1 for Name:Exact As Record
Birthdate:1856
source 1 for birthdate:Minnesota Death Records
listed as in source 1 for birthdate:1856
listed column in source 1 for birthdate:Birthdate
determined logic in source 1 for birthdate: Exact As Record
Birthplace:Minnesota,USA
source 1 for birthplace:Minnesota Death Records
listed as in source 1 for birthplace:Minnesota,USA
listed column in source 1 for birthplace:Birthplace
determined logic in source 1 for birthplace:Exact As Record
FathersName:Bob S.
source 1 for fathersname:Minnesota Death Records
listed as in source 1 for fathersname:Bob S.
listed column in source 1 for fathersname:fathers name
determined logic in source 1 for fathersname:Exact As Record
SpousesName:Sally Johnson
source 1 for spousesname:Minnesota Death Records
listed as in source 1 for spousesname:Sally Johnson
listed column in source 1 for spousesname:Spouses Name
determined logic in source 1 for spousesname:Exact As Record
Deathdate:feb 4
source 1 for deathdate:Minnesota Death Records
listed as in source 1 for deathdate:feb 4
listed column in source 1 for deathdate:Deathdate
determined logic in source 1 for deathdate:Exact As Record
Deathplace:Los A.,CA,USA
source 1 for deathplace:Minnesota Death Records
listed as in source 1 for deathplace:Los A., CA, USA
listed column in source 1 for deathplace:Deathplace
determined logic in source 1 for deathplace:Exact As Record

Record 2:
Name:John Henry Smith
source 1 for name: Smith Family Bible
listed as in source 1 for Name:John Henry Smith
listed column in source 1 for Name:Name
determined logic in source 1 for Name:Exact As Record
Birthdate:4 july 1856
source 1 for birthdate:Smith Family Bible
listed as in source 1 for birthdate:4 july 1856
listed column in source 1 for birthdate:birthdate
determined logic in source 1 for birthdate:Exact As Record
Birthplace:USA
source 1 for birthplace:Smith Family Bible
listed as in source 1 for birthplace:USA
listed column in source 1 for birthplace:birthplace
determined logic in source 1 for birthplace:Exact As Record
FathersName:Robert J. Smith
source 1 for fathersname:Smith Family Bible
listed as in source 1 for fathersname:Robert J. Smith
listed column in source 1 for fathersname:FathersName
determined logic in source 1 for fathersname:Exact As Record
SpousesName:Sally Jean Johnson
source 1 for spousesname:Smith Family Bible
listed as in source 1 for spousesname:Sally Jean Johnson
listed column in source 1 for spousesname:SpousesName
determined logic in source 1 for spousesname:Exact As Record
Deathdate:1930
source 1 for deathdate:Smith Family Bible
listed as in source 1 for deathdate:1930
listed column in source 1 for deathdate:Deathdate
determined logic in source 1 for deathdate:Exact As Record
Deathplace:CA,USA
source 1 for deathplace:Smith Family Bible
listed as in source 1 for deathplace:CA, USA
listed column in source 1 for deathplace:Deathplace
determined logic in source 1 for deathplace:Exact As Record

to become 1 record that says:
Name:John Henry Smith
source 1 for name: Minnesota Death Records
listed as in source 1 for Name: John S.
listed column in source 1 for Name:Husband
determined logic in source 1 for Name:Exact First Name and Exact Last
Name as source 2
source 2 for name: Smith Family Bible
listed as in source 2 for Name:John Henry Smith
listed column in source 2 for Name:Name
determined logic in source 2 for Name:Exact As Record
Birthdate:4 july 1856
source 1 for birthdate:Minnesota Death Records
listed as in source 1 for birthdate:1856
listed column in source 1 for birthdate:Birthdate
determined logic in source 1 for birthdate: Exact Year as source 2
source 2 for birthdate:Smith Family Bible
listed as in source 2 for birthdate:4 july 1856
listed column in source 2 for birthdate:birthdate
determined logic in source 2 for birthdate:Exact As Record
Birthplace:Minnesota,USA
source 1 for birthplace:Minnesota Death Records
listed as in source 1 for birthplace:Minnesota,USA
listed column in source 1 for birthplace:Birthplace
determined logic in source 1 for birthplace:Exact As Record
source 2 for birthplace:Smith Family Bible
listed as in source 2 for birthplace:USA
listed column in source 2 for birthplace:birthplace
determined logic in source 2 for birthplace:Exact country as source 1
FathersName:Robert J. Smith
source 1 for fathersname:Minnesota Death Records
listed as in source 1 for fathersname:Bob S.
listed column in source 1 for fathersname:fathers name
determined logic in source 1 for fathersname:First Name is Nick Name and
Last Name Exact as source 2
source 2 for fathersname:Smith Family Bible
listed as in source 2 for fathersname:Robert J. Smith
listed column in source 2 for fathersname:FathersName
determined logic in source 2 for fathersname:Exact As Record
SpousesName:Sally Jean Johnson
source 1 for spousesname:Minnesota Death Records
listed as in source 1 for spousesname:Sally Johnson
listed column in source 1 for spousesname:Spouses Name
determined logic in source 1 for spousesname:Exact First Name and Last
Name as source 2
source 2 for spousesname:Smith Family Bible
listed as in source 2 for spousesname:Sally Jean Johnson
listed column in source 2 for spousesname:SpousesName
determined logic in source 2 for spousesname:Exact As Record
Deathdate:feb 4 1930
source 1 for deathdate:Minnesota Death Records
listed as in source 1 for deathdate:feb 4
listed column in source 1 for deathdate:Deathdate
determined logic in source 1 for deathdate:Possible same year as source
2
source 2 for deathdate:Smith Family Bible
listed as in source 2 for deathdate:1930
listed column in source 2 for deathdate:Deathdate
determined logic in source 2 for deathdate:Possible same month and day
as source 1
Deathplace:Los A., CA, USA
source 1 for deathplace:Minnesota Death Records
listed as in source 1 for deathplace:Los A., CA, USA
listed column in source 1 for deathplace:Deathplace
determined logic in source 1 for deathplace:Exact As Record
source 2 for deathplace:Smith Family Bible
listed as in source 2 for deathplace:CA, USA
listed column in source 2 for deathplace:Deathplace
determined logic in source 2 for deathplace:Exact State and Country as
source 1
Glen (Guest)
on 2009-01-17 05:58
(Received via mailing list)
Hi Tim,

There is no out-of-box way to marge records in Rails framework.
However, by using ActiveRecord, you can do data operations like
comparing filed values, inserting new records, and deleting old
records.

I think you are asking very core part of your business, and I assume
no one can really answer what to do for your problem.  How do you
define "data is similar or same"?  If records matches, which record
should be left or creating new one?  Is this process happens in batch
mode or when user processed specific actions?  Thinking these
questions may help you to define "your algorithm". Once you come up
with your algorithm, you put it into your model and encapsulate the
process.

Hope this will help.

Glen
Brandon K. (Guest)
on 2009-01-17 07:13
(Received via mailing list)
On Fri, Jan 16, 2009 at 2:43 PM, Tim Dunn
<removed_email_address@domain.invalid> wrote:
>
> Hi I am Tim Dunn and am working on a web app to help people research
> their family history. I am wondering how to merge records from the same
> table into one record based on if they are exact or partial matches in
> any given set of fields.

You might want to check out this plugin:
http://github.com/collectiveidea/merger

Right now it doesn't have any of the logic for picking which which
fields to keep, but it will merge all the associations to the oldest
model and delete the newer ones.

    @person1.merge(@person2, @person3)


-- Brandon
--------------------------------------------------------------------------------
Training by Collective Idea: Refer a friend and get $100
http://training.collectiveidea.com – San Antonio, TX – Jan 20-23
This topic is locked and can not be replied to.