Select columns

Hi,

I have a model with a relation, let’s say something like this:




class Model1 extends CActiveRecord

{

    public function relations()

    {

        return array(

            'model2' => array( self::BELONGS_TO, 'Model2', 'model2_id' ),

        );

    }

}



Then, if I try to do a query, let’s say:


        

$criteria = new CDbCriteria( array(

    // THIS FAILS WITH "Active record "{class}" is trying to select an invalid column "model2.name""

    'select' => array( 't.*', 'model2.name' ),

    'with' => array( 'model2' ),

    // BUT THIS WORKS!! so the alias is fine, isn't it?

    'condition' => 'model2.name=\'a_name\'' ) );

return new CActiveDataProvider( __CLASS__, array( 'criteria' => $criteria ) );



So, it seems the alias may be used in "condition" but not in "select"? If this very same alias is used in the relations array like this:




class Model1 extends CActiveRecord

{

    public function relations()

    {

        return array(

            'model2' => array( self::BELONGS_TO, 'Model2', 'model2_id', 'select' => 'model2.name' ),

        );

    }

}



Then it works. Am I missing something? Or may it be a bug?

Thank you.

Try like that:




'with' => array( 'model2'=>array('select'=>'name') ),