Displaying 1 result from an estimated 1 matches for "be_friendly_to_friend".
2006 May 02
0
Self-referential MtoM implementation
...end
end
class Person < ActiveRecord::Base
has_and_belongs_to_many :friends,
:class_name => "Person",
:join_table => "friends_people",
:association_foreign_key => "friend_id",
:foreign_key => "person_id",
:after_add => :be_friendly_to_friend,
:after_remove => :no_more_mr_nice_guy
def be_friendly_to_friend(friend)
friend.friends << self unless friend.friends.include?(self)
end
def no_more_mr_nice_guy(friend)
friend.friends.delete(self) rescue nil
end
end
--
Posted via http://www.ruby-forum.com/.