Skip to content

Instantly share code, notes, and snippets.

@kent
Created July 27, 2010 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kent/492474 to your computer and use it in GitHub Desktop.
Save kent/492474 to your computer and use it in GitHub Desktop.
class Friend < ActiveRecord::Base
belongs_to :user
belongs_to :contact, :class_name => "User", :foreign_key => "contact_id"
# user befriends contact
def self.befriend(user,contact)
begin
HELPERS.set_add contact.id, user.id
HELPING.set_add user.id, contact.id
rescue
RedisLogger.info "Redis Exception"
end
end
end
class User < ActiveRecord::Base
has_many :friends, :dependent => :destroy
has_many :contacts, :through => :friends, :order => "created_at DESC", :dependent => :destroy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment