Okay folks, I’m feeling like a fool. I’m sure I’m not the first person
to run into this, but I can’t find the necessary info.
Basically I need to create two tables. The first to hold actual
content. And the second to link pairs of content records. For
example, a “persons” table and a “friends” table that pairs up two
person records. Obviously, I can’t have two fields in the friends
table named ‘person_id’. So how do I assign a field as a foreign key,
that isn’t named in the default format “table_id”?
Okay folks, I’m feeling like a fool. I’m sure I’m not the first person
to run into this, but I can’t find the necessary info.
Basically I need to create two tables. The first to hold actual
content. And the second to link pairs of content records. For
example, a “persons” table and a “friends” table that pairs up two
person records. Obviously, I can’t have two fields in the friends
table named ‘person_id’. So how do I assign a field as a foreign key,
that isn’t named in the default format “table_id”?
You could also use a has_and_belongs_to_many association if your mapping
table really just contains the 2 person ids.
Like igotimac implied in his comment, you can name your foreign keys
whatever you want, just reference them explicitly when you create your
association using the options macros for the association (foreign_key=>,
class_name=>, etc)