Engine23
blogBannerImage
By Engine23

Yii getCommandBuilder() to get the select statement that is built

$model = BanksToSalespeople::model();

$addresses = array();

$criteria = $model->dbCriteria;

$criteria->with = "users";

$criteria->together = true;

$criteria->join ="LEFT JOIN users ON t.userID = users.id";

$criteria->select = 'email';

$criteria->condition = "t.bankID = '$bankID' AND users.email != ''";

// This is how to get the query that is built from the Yii magic command builder:

$query = $model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();