I create a portal based on the framework cakephp 3 and admin panel made as a plugin to separate the files from the rest. The tables, which will cover only the admin panel I put in separately created database 'admin'.
I have correctly configured database connections in config/app.php.
'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'user',
            'password' => 'password',
            'database' => 'portal',
            'encoding' => 'utf8',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'log' => false,
        ],
        'admin' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'user',
            'password' => 'password',
            'database' => 'admin_portal',
            'encoding' => 'utf8',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
            'quoteIdentifiers' => false,
            'log' => false,
        ],
    ],
So I have plugin Admin.
I created inside plugin 2 controllers:
plugins/Admin/src/Controller/AdminController.php
<?php
namespace Admin\Controller;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
class AdminController extends Controller {
    public function initialize() {
        parent::initialize();
        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
    }
}
plugins/Admin/src/Controller/MainController.php
<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
class MainController extends AdminController {
    public function dashboard() {
        $this->loadModel('Messages');
        $results = $this->Messages->find('all');
        pr($results);
    }
}
And I created model for table Messages
<?php
namespace Admin\Model\Table;
use Admin\Model\Entity\Message;
use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class MessagesTable extends Table {
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->table('messages');
        $this->displayField('name');
        $this->primaryKey('id');
    }
    public static function defaultConnectionName()
    {
        return 'admin';
    }
}
When I fire dashboard action from MainController instead of results from messages table I got an error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'portal.messages' doesn't exist
So the CakePHP is looking for the table messages in the default database instead of in the "admin_portal" table.
What am I doing wrong? Somehow cake doesn't respect defaultConnectionName() method in plugin model. I tried use this method in some model in /src (not in plugin) - then it worked correctly.