Yii2 - get query from ActiveRecord

yii2
voted: 1
vote
php framework yii2 activerecord

For get query from ActiveRecord:

<?php
// don't use ->all() nor ->one() to not execute query:
$activeRecordExpression = Model::find();
$query = $activeRecordExpression->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql;
//then echo it or do something with it
?>
working url: not entered
version: 2 and maybe others
Leave a Comment:
Characters left:
No comments yet.