From: Kirk Haines Date: 2004-06-05T01:25:14+09:00 Subject: Re: [ANN] Active Record 0.8.2: Inheritable callback ques On Sat, 5 Jun 2004 00:41:55 +0900, Carl Youngblood wrote > I usually prefer to name my primary ID columns id just to > avoid confusion. For example, the primary key of the user table is > called userid. On many-table JOINS it gets confusing to have a lot > of IDs floating around. So I agree that being able to change the id > column to something else would be handy. Another thing that some > people might be confused about is when you have a table whose > primary key consists of multiple columns that are combinatorially > unique. In these cases I think the solution is to add an integer > primary key and use it for the ID column, and then make a unique > index across the fields that you wish to be combinatorially unique. I still haven't delved into ActiveRecord's code as much as I want to, but in theory these things should be supportable. Kansas, which is similar to ActiveRecord but takes a few different approaches, allows things like this: create table jukebox ( id int unsigned primary key, serial_number int unsigned unique, blah blah blah) create table albums ( id int unsigned primary key, jukebox_serial int, blah blah blah) create table tracks ( id int unsigned primary key, album_id int, blah blah blah) class Jukebox to_many(:albums, :Albums, :jukebox_serial, :serial_number) end class Albums to_many(:tracks, :Tracks, :album_id) belongs_to(:jukebox, :Jukebox, :serial_number, :jukebox_serial) end class Tracks belongs_to(:album, :Albums, :album_id) end So, a Jukebox has many Albums. However, instead of using Jukebox's primary key, serial_number on the Jukebox maps to jukebox_serial, which is simply a unique key, on the Album. Albums have many tracks, and are correlated through the primary key on Album and the album_id field on Track. An Album also belongs to a Jukebox, and is correlated via the jukebox_serial field on the Album and the serial_number field on the Jukebox. Tracks belong to an Album, and are correlated via the album_id field of the Track to the primary key of the Album. I don't yet have complete support for multiple field primary keys, but that's not far off. There is a release with some added documentation explaining the stuff above, among other things, coming hopefully by the end of the day. Kirk Haines