Last active
August 14, 2023 09:16
-
-
Save pastuhov/f8a13d35e2181987da9c to your computer and use it in GitHub Desktop.
Use Master yii2 activerecord trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\models; | |
trait MasterTrait | |
{ | |
public static function getDb() | |
{ | |
$connection = clone \Yii::$app->getDb(); | |
$connection->enableSlaves = false; | |
return $connection; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends ActiveRecord | |
{ | |
use MasterTrait; | |
} | |
/** | |
* Fetch all users from master server | |
*/ | |
User::find()->all(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment