Created
July 29, 2010 03:03
-
-
Save kent/497108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| relationship = find_by_user_id_and_contact_id(user.id,friend.id) | |
| if relationship.nil? | |
| transaction do | |
| Friend.create(:user => user, :contact => contact) | |
| end | |
| add_to_denormalized_list(user,contact) | |
| end | |
| end | |
| def self.add_to_denormalized_list(user,contact) | |
| begin | |
| HELPERS.set_add contact.id, user.id | |
| HELPING.set_add user.id, contact.id | |
| rescue e | |
| 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