the standard user_id key exists but i would also like to use another
key for my links. i am not sure how to implement this. also i don't
want any auto incrementing of this second primary key that i would
like to use for my relationships.
if there is a good db, model, relationship tutorial out there i would
love to know about it.
are you mixing up "primary keys" and foreign keys" ?
Every Rails model has, by default, an auto-incrementing "id" column as
primary key, and columns like "user_id" are no primary keys, but
foreign keys to link to related objects/rows in other tables. those
are not auto-incrementing and not primary. and you can have as many od
them as you want.
anyways, if your really need 2 primary keys in a model, try this:
It depends on the association type. Every table has an id on it
automatically (hopefully).
say you have users and groups.
a group has many users
table name users, has a column called group_id
class User < AR
belongs_to :group
end
table name groups
class Group < AR
has_many :users
end
if you wanted to spell out the foreign key, you'd put has_many :users,
foreign_key :group_id. The belongs_to will be belongs_to :group,
foreign_key :user_id