class User < ActiveRecord::Base
has_many :sent_invites, :class_name => "Invite", :foreign_key => :inviter_id
has_many :inviteds, :through => :sent_invites
has_one :invite, :foreign_key => :invited_id
has_one :inviter, :through => :invite
end
Sidebar, it is generally a good idea to add indexes to foreign keys like so:
class CreateInvites < ActiveRecord::Migration
def change
create_table :invites do |t|
t.references :invited
t.references :inviter
t.index :invited_id
t.index :inviter_id
t.timestamps
end
end
end