1
0
Fork 0

Disallow self reference friend

This commit is contained in:
Andrew Tomaka 2014-10-27 12:27:32 -04:00
parent 1919d618aa
commit b3640e078c

View file

@ -3,4 +3,11 @@ class Friendship < ActiveRecord::Base
belongs_to :friend, class_name: 'User' belongs_to :friend, class_name: 'User'
validates_uniqueness_of :friend_id, :scope => :user_id validates_uniqueness_of :friend_id, :scope => :user_id
validate :disallow_self_reference
def disallow_self_reference
if friend_id == user_id
errors.add(:friend_id, 'cannot refer back to self')
end
end
end end