How to define relationship for user-to-user friendship

Jesse wrote:

Was wondering how I would define this relationship in my User model if: A friendship relationship consists of two users.

class CreateUsers < ActiveRecord::Migration    def self.up      create_table :users do |t|        t.column :name, :string, :limit => 80, :null => false        t.column :friend_id, :integer      end    end

   def self.down      drop_table :users    end end

class User < ActiveRecord::Base

   belongs_to :friend,               :class_name => "User",               :foreign_key => "friend_id"

end

[276]script/console Loading development environment. >> john = User.create(:id => 1, :name => "John") >> jane = User.create(:id => 2, :name => "Jane") >> john.friend = jane >> jane.friend = john >> john.friend_id => 2 >> jane.friend_id => 1