class ActiveQuery extends \yii\db\ActiveQuery { private $_noLoadBalance = false; /** * , * * @return $this */ public function noBalance() { $this->_noLoadBalance = true; return $this; } /** * @inheritdoc */ public function createCommand($db = null) { /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; if ($db === null) { $db = $modelClass::getDb(); } if ($this->sql === null) { list ($sql, $params) = $db->getQueryBuilder()->build($this); } else { $sql = $this->sql; $params = $this->params; } $comment = ''; if (true === $this->_noLoadBalance) { $comment = '/*NO LOAD BALANCE*/'; } return $db->createCommand($comment . $sql, $params); } }
$user = User::find()->where([ User::ATTR_ID => $userid, ]) ->noBalance() ->one();
Source: https://habr.com/ru/post/307248/
All Articles