Can not use different db connection in my AR model

I have two database connections defined:

db:




<?php


return [

    'class' => 'yii\db\Connection',

    'dsn' => 'mysql:host=localhost;dbname=test',

    'username' => 'root',

    'password' => 'root',

    'charset' => 'utf8',


    'enableSchemaCache' => true,

    'schemaCacheDuration' => 3600,

    'schemaCache' => 'cache',

];

dbWithoutUtf8:




<?php


return [

    'class' => 'yii\db\Connection',

    'dsn' => 'mysql:host=localhost;dbname=test',

    'username' => 'root',

    'password' => 'root',

    'charset' => 'latin1',


    'enableSchemaCache' => true,

    'schemaCacheDuration' => 3600,

    'schemaCache' => 'cache',

];

Inside my web.php I am including both:


'dbWithoutUtf8' => require(__DIR__ . '/dbWithoutUtf8.php'),

'db' => require(__DIR__ . '/db.php'),

And in my AR model I am overriding getDb method:


public static function getDb() 

{

    return Yii::$app->dbWithoutUtf8;

} 

In same model I have query that is using db connection insted of dbWithoutUtf8. Any clues why ?


public static function getNews()

{

    return self::find()->joinWIth(['document'])->all();

}

In model, instead self:: use static::

Thanks, but it wasn’t that. I have figured it out. I had to use :


public static function getDb() 

{

   return Yii::$app->dbWithoutUtf8;

}

in every model that was included in my join query, or at least in the last one that I was pulling some data from.