I have the query:
$popular = self::find()
->from(self::tableName() . ' as t')
->with('user');
When I try to print sql:
$popular->createCommand()->rawSql
It gives me:
SELECT * FROM "themes" "t"
So can I get full raw query with "join":
SELECT * FROM "themes" "t" LEFT JOIN "users" u ON u.user_id = t.author_id
It's already answered here.
You can var_dump
generated SQL for ActiveQuery
instances like this:
var_dump($query->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql);
However, I recommend to use built-in debug model and panel.
P.S. As for your particular query - with()
does not perform JOIN
, instead it performs additional query and fills relation attributes with the actual related records. To use JOIN
, you need explicitly specify it for example with joinWith()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With