title: CakePHP 3.1 plugin join tables not using custom datasource
body: <p>For some reason, when I use containable with a join table in a plugin, Cake uses the default datasource instead of the custom one.
  I've been all over stackoverflow and Google, and tried everything I could find to no avail.</p>
  
  <p>I'm trying to create a plugin that uses its own datasource:</p>
  
  <p>plugins/Vorien/NPCData/config/app.php:</p>
  
  <pre><code>return [
      'Datasources' =&gt; [
          'npcdata' =&gt; [
              'className' =&gt; 'Cake\Database\Connection',
              'driver' =&gt; 'Cake\Database\Driver\Mysql',
              'persistent' =&gt; false,
              'host' =&gt; 'localhost',
              'username' =&gt; 'npcdata',
              'password' =&gt; '********',
              'database' =&gt; 'npcdata',
              'encoding' =&gt; 'utf8',
              'timezone' =&gt; 'UTC',
              'flags' =&gt; [],
              'cacheMetadata' =&gt; true,
              'log' =&gt; false,
              'quoteIdentifiers' =&gt; true,
              'url' =&gt; env('DATABASE_URL', null),
          ],
      ],
  ];
  </code></pre>
  
  <p>plugins/Vorien/NPCData/config/bootstrap.php:</p>
  
  <pre><code>try {
      Configure::config('npcdata', new PhpConfig(Plugin::path('Vorien/NPCData') . 'config/'));
      Configure::load('app', 'npcdata');
      ConnectionManager::config(Configure::consume('Datasources'));
  } catch (\Exception $e) {
      exit($e-&gt;getMessage() . "\n");
  }
  </code></pre>
  
  <p>I used bake to create everything with the parameters:</p>
  
  <pre><code>  -p Vorien/NPCData -c npcdata
  </code></pre>
  
  <p>My join tables look like:</p>
  
  <pre><code>$this-&gt;belongsTo('Personas', [
      'foreignKey' =&gt; 'persona_id',
      'className' =&gt; 'Vorien/NPCData.Personas'
  ]);
  $this-&gt;belongsTo('Archetypes', [
      'foreignKey' =&gt; 'archetype_id',
      'className' =&gt; 'Vorien/NPCData.Archetypes'
  ]);
  </code></pre>
  
  <p>And have:</p>
  
  <pre><code>public static function defaultConnectionName()
  {
      return 'npcdata';
  }
  </code></pre>
  
  <p>Running a hasOne or hasMany:</p>
  
  <pre><code>$persona = $this-&gt;Personas-&gt;get($id, [
      'contain' =&gt; ['People']
  ]);
  </code></pre>
  
  <p>When I try to run anything with a HABTM:</p>
  
  <pre><code>$persona = $this-&gt;Personas-&gt;get($id, [
      'contain' =&gt; ['Archetypes']
  ]);
  </code></pre>
  
  <p>I get:
      Error: SQLSTATE[HY000] [1045] Access denied for user 'my_app'@'localhost' (using password: YES)
  with the Auto-Tables error for PersonasArchetypes</p>
  
  <p>I dug around a lot until I realized that the key was 'my_app'@'localhost' which meant that even with the defaultConnectionName set in PersonasArchetypesTable Cake was using the 'default' connection only for join tables.  When I set the default connection in config/app.php everything works.  Of course that won't work for a plugin.</p>
  
  <p>Note: The join table isn't alphabetical but that was changed to optional in 3.0.  I did try renaming the join tables anyway.</p>
  
  <p>Has anyone else run into this?  Could it be a bug?  Or am I just missing something?</p>
  
  <p>EDIT:  I've also tried adding the database name before the table in all three Table files of the HABTM.  (database.table instead of just table)</p>