View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
class User < ActiveRecord::Base has_many :friends, :dependent => :destroy has_many :contacts, :through => :friends, :order => "created_at DESC", :dependent => :destroy end
class Friend < ActiveRecord::Base belongs_to :user belongs_to :contact, :class_name => "User", :foreign_key => "contact_id" 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 end end end