Forum: Ruby on Rails Legacy Data without Primary Keys

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.
Vodex N. (Guest)
on 2005-12-27 21: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
record

* Something else...

Thx!
Vodex N. (Guest)
on 2005-12-28 15: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
belongs_to.

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.