Q:

Yii CActiveDataProvider Join and select from joined table

I have the following example code:
                $dataProvider = new CActiveDataProvider('firstTable', 
                    array('criteria' => array(
                        'select' => 't.firstfield,secondTable.secondfield',
                        'join' => 'join secondTable on secondTable.id=t.secondTable_id',
                    ),
                    'pagination' => array(
                        'pageSize' => 10,
                    ),
                ));
                $results=$dataProvider->getData();

After running the code above, firstField (from the model table - firstTable) is available in the object, but secondField (from the joined table - secondTable) is not.
Can anyone provide assistance on what is wrong with the code or why the "select" option is not picking up the secondField?

A:

it would be better if you use CDbCriteria, that has a better solution to join table with the help of relations. I can show the example with CDbCriteria.
$criteria = new CDbCriteria;
$criteria->select = 'firstfield';
$criteria->with = array('secondTable_relation'=>array('select'=>'secondfield'));
$dataProvider = new CActiveDataProvider('firstTable', 
                    array('criteria' => $criteria,
                    'pagination' => array(
                        'pageSize' => 10,
                    ),
                ));
                $results=$dataProvider->getData();

secondTable_relation is a relation name with secondTable.

