Forum: Ruby on Rails multiple keys table

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.
A6d777dcac0572d2b5288b1c41cbcd45?d=identicon&s=25 Amir Lidor (shiko)
on 2006-02-28 15:26
probablly a newbie question:
Rails does not support a table with multiple keys ???
it seems that the ActiveRecord set_primary_key method can only set the
column name... (hope i'm wrong there)

example:
table A - P.K id, string name
table B - P.K id, string name
table C - P.K a_id and b_id, both are also foreign keys.

Thanks,
Amir.
317aad7f9f0b69a440faca74bbe22b20?d=identicon&s=25 Jakob Skjerning (Guest)
on 2006-02-28 16:11
(Received via mailing list)
amir lidor wrote:
> probablly a newbie question:
> Rails does not support a table with multiple keys ???
> it seems that the ActiveRecord set_primary_key method can only set the
> column name... (hope i'm wrong there)

Sorry to be the carrier of bad news, but you are correct as far as I
know.
F59329dc91cba06600ff65c85fd3e93c?d=identicon&s=25 Anthony Green (acgreen)
on 2006-02-28 16:19
amir lidor wrote:
> probablly a newbie question:
> Rails does not support a table with multiple keys ???
> it seems that the ActiveRecord set_primary_key method can only set the
> column name... (hope i'm wrong there)
>
> example:
> table A - P.K id, string name
> table B - P.K id, string name
> table C - P.K a_id and b_id, both are also foreign keys.

What is the relationship between tables A and B  ?
One to many, many to one, many to many ?
I just wondered if your normalization was correct..
_tony
A6d777dcac0572d2b5288b1c41cbcd45?d=identicon&s=25 Amir Lidor (shiko)
on 2006-03-01 07:57
Anthony Green wrote:
> amir lidor wrote:
>> probablly a newbie question:
>> Rails does not support a table with multiple keys ???
>> it seems that the ActiveRecord set_primary_key method can only set the
>> column name... (hope i'm wrong there)
>>
>> example:
>> table A - P.K id, string name
>> table B - P.K id, string name
>> table C - P.K a_id and b_id, both are also foreign keys.
>
> What is the relationship between tables A and B  ?
> One to many, many to one, many to many ?
> I just wondered if your normalization was correct..
> _tony

The relation is many to many.
I talked with a friend though and he explained me that it's really bad
to use multiple-keys tables, and that if i assign another primary key
column, even if there will be multiple identical (value-wise of the a_id
and b_id columns) rows, RoR will ignore them when performing Joins.
so i understand what should i do, I am just left with the question (out
of curiosity) about Rails supporting multiple-keys tables...

Thanks,
Amir.
Bc80625db60e9db4394c51d6c1892b49?d=identicon&s=25 Derrick Spell (Guest)
on 2006-03-01 14:58
(Received via mailing list)
On Mar 1, 2006, at 1:57 AM, amir lidor wrote:

>>> table B - P.K id, string name
> column, even if there will be multiple identical (value-wise of the
> a_id
> and b_id columns) rows, RoR will ignore them when performing Joins.
> so i understand what should i do, I am just left with the question
> (out
> of curiosity) about Rails supporting multiple-keys tables...
>
> Thanks,
> Amir.
>

It sounds like you want a composite primary key, i.e. the combination
of (a_id, b_id) form the primary key for table C.
No, this is not supported in Rails.  Such practice has fallen out of
favor in recent years, and some database servers do not even support
it.  There is still much debate, but Rails has taken the position of
rejecting composite primary keys.

-Derrick Spell
This topic is locked and can not be replied to.