title: How does self.class.where retrieve information from the database?
body: <p>One object orientated way to retrieve information from the database is to use those three methods, chained together.</p>
  
  <p>You can create an instance method like this:</p>
  
  <pre><code>def "find_friend"
      self.class.where({friend_id: user_id})
  end
  </code></pre>
  
  <p>and then call it like this:</p>
  
  <pre><code># @user_friendship == &lt;UserFriendship id: 1, friend_id: 2, user_id: 1&gt;
  
  @user_friendship.find_friend
  </code></pre>
  
  <p>and if we have a user_friendships table like this:</p>
  
  <pre><code>| id | friend_id | user_id |
  
  | 1  | 1         | 3       |
  | 2  | 2         | 1       |
  | 3  | 3         | 2       |
  </code></pre>
  
  <p>Then the find_friend method would return the second record (The one with an id of 2)</p>
  
  <pre><code>@user_friendship.find_friend #=&gt; &lt;UserFriendship id: 2, friend_id: 2, user_id: 1&gt;
  </code></pre>
  
  <p>Now, firstly is my understanding correct?</p>
  
  <p>Secondly, how does this actually work? <code>self.class.inspect</code> simply returns what appears to be a hash of the model table's schema:</p>
  
  <pre><code>self.class.inspect #=&gt; `UserFriendship(id: integer, friend_id: integer, user_id: integer)`
  </code></pre>
  
  <p>So how is it possible to run a query on this simple hash?</p>
  
  <pre><code>self.class.where({friend_id: user_id})
  </code></pre>