Rails: Multi-Column Primary Key for ActiveRecord

B

Brian Takita

Hello,

Is there a way to set an ActiveRecord object to point to a table with a
multi-column primary key?

Thank you,
Brian Takita
 
B

Brian Takita

I get the impression that the current implementation does not support a
primary key with multiple columns.

Looking at base.rb, the primary_key variable is used in such a way that
a single column name is expected.
 
D

David Heinemeier Hansson

Is there a way to set an ActiveRecord object to point to a table
with a
multi-column primary key?

Not really, no. Active Record was designed for a single column
primary key and that assumption runs pretty deep. AR is not a Data
Mapper, so you have to be within a reasonable vicinity of its
assumptions to enjoy it.
 
B

Brian Takita

David,

First of all, your Rails framework is well done and has revamped my
interest in Ruby, which has been a very good thing. Thank you.

I was thinking that we can get around this single column key limitation
by adding a incrementing int column with a unique index to the table.
I havn't tried it, but it makes sense that it would work.

Brian
 
B

Brian Takita

David,

First of all, your Rails framework is well done and has revamped my
interest in Ruby, which has been a very good thing. Thank you.

I was thinking that we can get around this single column key limitation
by adding a incrementing int column with a unique index to the table.
I havn't tried it, but it makes sense that it would work.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top