I have been working on making a self-referential habtm relationship that
uses a join model because I want to store info about the relationship. I
have been using Chad Fowler's "Rails Recipes" as a guide. So far I have
had little luck. Here is what I have that works a little, but not
class User < ActiveRecord::Base
:before_add => :check_self,
:after_add => :be_friendly_to_friend,
:after_remove => :no_more_mr_nice_guy
friend.friends << self unless friend.friends.include?(self)
friend.friends.delete(self) rescue nil
if self==friend then ...
I want to prevent duplicate entries. When I do something like this
Then it is adding all the friends of u2 even if some of them were
And it is also adding itself as friend.
Can anyone tell me what I can write in before_add callback so that I can
prevent record from creation if it is meeting some condition.