I’ll start w/ the User class.
class User < ActiveRecord::Base
:class_name => “User”, # 
:join_table => “users_friends”, # 
:foreign_key => “user_id”, # 
:association_foreign_key => “friend_id” # 
 Specify the class name since it differs from the association name.
 Specify the join table since you’ll name it something other than
users_users, which is what Rails would assume.
 Specify the foreign key back to this user; not necessary as Rails
assume it in this case, but I thought I’d show it.
 Specify the foreign key that will hold the ids of this user’s
Here’s the migration to create the join table.
class … < ActiveRecord::Migration
create_table :users_friends, :id => false, :force => true do |t|
As you can see, it’s just a simple join table for tracking the
from user to user (friend).
I’m sure you’ll want to tweak the User class and migration a bit, but I
you get the idea.