Disallow self reference friend
This commit is contained in:
parent
1919d618aa
commit
b3640e078c
1 changed files with 7 additions and 0 deletions
|
@ -3,4 +3,11 @@ class Friendship < ActiveRecord::Base
|
|||
belongs_to :friend, class_name: 'User'
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue