A conditional active record query
Some notes:


if boolean then true else false end -> boolean.
UserRelation.where(user_id: self.id).where(with_user_id: user.id) -> UserRelation.where(user_id: self.id, with_user_id: user.id)
active_record_collection.count &gt; 0 -> active_record_collection.exists?
I don't understand why you have to check both ways, a "coach - student" relationship looks unidirectional.


Anyway, if you set up the coach_students association, you may write something like this:

def coach_of?(user)
  coach_students.where(with_user_id: user).exists? || 
    user.coach_students.where(with_user_id: self).exists?
end