Yii 1, get SQL generated by CDbCriteria
<p>got a problem, I need to get all ids of models (not only visible but all models) in CGridView. For that I use its DataProvider - get a criteria from it and pass it to command builder</p>

<pre><code>$criteria = $dataProvider-&gt;getCriteria();
$criteria-&gt;select = 'id';
$command = Y::db()-&gt;commandBuilder-&gt;createFindCommand('tableName', $criteria);
$ids = $command-&gt;queryColumn();
</code></pre>

<p>It is working fine until we got filtering via related tables. For example user adds a number to a filter of the grid - "House Number" = 24. When it happens related table - "address" adds to <code>$criteria-&gt;with</code> and "address.home_number = 24" adds to <code>$criteria-&gt;condition</code>.</p>

<p>ActiveRecord automatically parses the "with" property of criteria and apply joins, so our condition would be fine with it, but CommandBuilder - not. I can't use AR for it, since it is deadly slow. I must use Builder, but I can't make joins, there could be more than 20 filters applied.</p>

<p>If I could get SQL generated by AR and then pass it to Builder - it would be great.</p>