def contact_request(contact) unless self == contact || Connection.where(user: self, contact: contact).exists? transaction do Connection.create(user: self, contact: contact, status: :pending) Connection.create(user: contact, contact: self, status: :requested) end end end
def accept_request(contact) transaction do Connection.find_by(user: self, contact: contact, status: [:requested])&.accepted! Connection.find_by(user: contact, contact: self, status: [:pending])&.accepted! end end