YII activerecord仅选择特定字段

时间:2013-03-29 08:03:13

标签: activerecord yii

我想只获取指定的字段,但是当我这样做时:

 $criteria = new CDbCriteria();
 $criteria->condition = 't.DeletionMark = 0';
 $criteria->select = 't.Description, address.Description, city.Description';
 $data = WCatalogInternetCounterparties::model()->with('internetCounterpartyAddresses.address.city')->findAll($criteria);

Active Record使用select Condition

中的所有字段生成查询

1 个答案:

答案 0 :(得分:0)

这是因为您使用的是Active Records,只能使用DAO获得所需的字段。

Yii::app()->db->createCommand()
    ->select('t.Description, address.Description, city.Description')
    ->where('t.DeletionMark = 0')
    ->from('w_catalog_internet_counterparties')
    ->with('internetCounterpartyAddresses.address.city')
    ->queryAll();