title: CakePHP joining Models between two tables, twice
body: <p>I have a question about how to set up the relations between two models when they join to each other in two different regards.</p>
  
  <p>I'll give an example of the problem I've got:</p>
  
  <pre><code>Users (id, name)
  Messages (id, message, from_user_id, to_user_id)
  </code></pre>
  
  <p><em><sub>(In my case, it's not users nor messages, but this hopefully illustrates the problem in a simpler way)</sub></em></p>
  
  <p>Users can send messages to each other, and each Message has a User who sent it and a User who will receive it. I'm trying to figure out the Model relations:</p>
  
  <pre><code>class User extends AppModel {
      var $hasMany = array("Message");
  }
  
  class Message extends AppModel {
      var $belongsTo = array("User");
  }
  </code></pre>
  
  <p>I'm also not sure how the fields should be named in the database so CakePHP will pick up the relationship properly.</p>