Loading A Column Subset Of A Database Table

I’ve just realized that my Model (an implementation of GxActiveRecord) loads all columns from the table. I thought it loads the one I had defined only.

How can I change my model or the kind I use it (currently I call model()->findByPk(…)) to only load some of the columns from the table? I thought about creating a view and an own model with the columns I need but that feels like a bad workaround.

one mistake: there should be ‘select’ association key of course:




class MyModel extends CActiveRecord {

...

public function scopes() {

  $alias = $this->getTableAlias( true );

  return array(

    'listColumns'=>array( 'select'=>"$alias.column1, $alias.column2" ),

    ...

  );

}

...




$obj = MyModel::model()->listColumns()->findByPk( $id );



Thank you so much redguy, that was what I was looking for :slight_smile:

thank you!