I'm browsing github looking at cool code, but don't understand what this code does:

I understand that there are 2 belongs\_to associations, but I don't understand what the 'self.request' method means and what it does.

Also, isn't 'transaction' meant for SQL database queries and not ruby code?

Could someone please clarify?

```
class Friendship < ActiveRecord::Base
  belongs_to :friend, :class_name => "User", :foreign_key => "friend_id"
  belongs_to :user

   def self.request(user, friend)
      unless user == friend or Friendship.exists?(user, friend)
          transaction do
              create(:user => friend, :friend => user, :status => 'requested')
              create(:user => user, :friend => friend, :status => 'pending')
          end
      end
  end

```