JSON encode of relational query

Hi there,

I started to work with Yii recently and still have a lot to learn. One problem I came across:

I use relational query to pull data like this:


then I feed the data to jqGrid with (I skipped steps here where I fill $page, $total & $records)

$data = array('total' => $total, 'page' => $page, 'records' => $records, 'rows' => $models);

$json_data = new CJSON;

echo $json_data->encode($data);

Unfortunately, json_encode uses only Parent records and does not attach joined Child

I came up with the following solution:


foreach($models as $model) {



and it works

But I don’t like because I’m not using Yii power.

Is there a better (Yii) way to do that?



CHtml::encodeArray package does a very nice job of helping with that see