title: Self linking model in cakePHP 3 and retrieving data from the join table
body: <p>im creating a WebApp with cakePHP 3.0.</p>
  
  <p>I have a User Model and Table which has and belongs to many Users.</p>
  
  <p>So i set up tables according to cake conventions: </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `users`
  (
  user_id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  );
  </code></pre>
  
  <p>and the JOIN table:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `users_users`
  (
  supervisor_id int,
  employee_id int,
  FOREIGN KEY (supervisor_id) REFERENCES users(user_id),
  FOREIGN KEY (employee_id) REFERENCES users(user_id)
  );
  </code></pre>
  
  <p>In my UserTable.php i created these associations:</p>
  
  <pre><code>    $this-&gt;table('users');
      $this-&gt;primaryKey('user_id');
  
      $this-&gt;belongsTo('Users', [
                  'foreignKey' =&gt; 'user_id',
                  'joinType' =&gt; 'INNER'
     ]);
  
      $this-&gt;belongsToMany('Supervisors', [
                  'className' =&gt; 'Users',
                  'targetForeignKey' =&gt; 'supervisor_id'
      ]);
      $this-&gt;belongsToMany('Employees', [
                  'className' =&gt; 'Users',
                  'targetForeignKey' =&gt; 'employee_id'
      ]);
  </code></pre>
  
  <p>Now in a new model method i want to get the Supervisors of one employee: </p>
  
  <pre><code>public function getSupervisorEmail($user_id) {
          $supervisors = $this-&gt;Employees-&gt;Supervisors-&gt;find()-&gt;select(['user_id']);
          debug($supervisors);
          return $supervisors;
      }
  </code></pre>
  
  <p>I put sample data in my users_users Table but i dont know how i can access these entries. The query in the function above doesnt do what i expect it to do. It just returns a record from my Users Table without joining with users_users Table what i dont understand because i set all up according to naming conventions of cakePHP 3...</p>
  
  <p>How can i access my join Table and get associated records? EG get Supervisors associated to user with user_id 1. I tried different querys but none used my join table.</p>
  
  <p>Thanks for answers!</p>