Forum: Ruby on Rails Legacy Data without Primary Keys

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
10630868cfdcd768be7d5732b545cf3b?d=identicon&s=25 Vodex None (vodex)
on 2005-12-27 20:24
(Received via mailing list)
Hi all. I'm importing some legacy data via ActiveRecord. However, it has
no primary key and I don't want duplicates - I am reasonably sure the
combination of two certain fields are unique, though.

What's the best practice & how's it done pls?

* Make a string id field and concatenate the two fields (or whatever I
want for an ID) in it

* Set the two fields to be primary keys, Rails picks it up, and don't
use find()

* Manually check with find_or_create_by_name_and_date(params) for each

* Something else...

10630868cfdcd768be7d5732b545cf3b?d=identicon&s=25 Vodex None (vodex)
on 2005-12-28 14:07
(Received via mailing list)
Ah, I forgot to mention that some fields should be referenced by a
foreign key.

i.e. the data is distinguished by Time & Place and Place is itself a

When importing the data, it needs to create new Places - I take it I'd
have to use a find_or_create_by_name on the Place object, and then do
one of the options below? Sorry, still getting to grips with this.
This topic is locked and can not be replied to.