Generic-user-small Martin Moora... 4 posts

I am having a little problem with a project that I am working on because I have two tables that need to be joined by a primary key, but the primary key is not an integer. I am trying to create a search engine for political contributions and the donations all have one “committee id” that is linked to a “committee”. The problem is that the every committee looks like this: C00001234 and in some cases H00VA987.

I tried to overide the process by appointing another column as my primary key, but when I do this, the column is coming up nil.

In theory I know this should be easy, but I think the problem is the that my primary key is not an integer.

Any suggestions?

 
Dscn5781_small Michael Matt... 8 posts

I’m no expert on the subject but this might help.

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/3f2ca213e4c6332b/84154f5ed6117221?lnk=raot

 
M_v_shokhirev_small Mikhail V. S... 19 posts

Martin!
1. If you decide which primary key to use, then do chhose a surrogate integer PK: it’ll save you much time in future.
2. Before appointing another column as the primary key, you needed to populate it by unique integer values (e.g. renumber the records).
3. If you work with a legacy DB, in which you can’t switch to another PK, it’s possible to use a non-numeric PK. But you’ll have to write a method for generating the keys to new records (def before_create; self.id = generate_next_id; end).

 
Generic-user-small Martin Moora... 4 posts

Mikhail,

Thanks for the advice. I have put this down for a few weeks and will try it again with a fresh approach.

Thanks!

Marty

4 posts, 3 voices