title: Yii2 conditional join on two foreign keys to same table
body: <p>I have two tables in the database, namely "user" and "user_user" which links users to users (many to many)</p>
  
  <p>in user_user there are two columns "user_id_0" and "user_id_1"</p>
  
  <p>I need to get all users where the current logged in user id is equal to either
  user_id_0 OR user_id_1.</p>
  
  <p>I can achieve this simply with sql:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select * from user u
      inner join user_user uu 
      on uu. user_id_0 = u.id
         or uu.user_id_1 = u.id
      [where u.id = 1]
  </code></pre>
  
  <p>In Yii2 I'm stuck with something like this:</p>
  
  <p>($this would be of type User)</p>
  
  <pre><code>$this-&gt;hasMany(User::className(), ['id' =&gt; 'user_id_0'])
          -&gt;viaTable('user_user', ['user_id_0' =&gt; 'id'],
             function($query) {
                $query-&gt;orOnCondition(['user_id_1' =&gt; 'id']);
           });
  </code></pre>
  
  <p>Now this can't work as hasMany() links to only one foreign key. How do I do something like the SQL above? To join two foreign keys with 'or'.</p>
  
  <p>I this possible or would you suggest a different database design? The goal here is really to enable users have "friends" or "connections" to other users like you would in a social network.</p>