mysqlyiicustom-fieldscustomcolumncactivedataprovider

Yii - using MySQL AS clause field


Let's say I want to have a provide CActiveDataProvider for a CGridView. I need to put a SUM(invitesCount) AS invites into a Provider result. How to retrieve it? I guess I cannot just use $dataProvider->invites?


Solution

  • You need to specify the following in your relationinvites

    'invites '=>array(self::BELONGS_TO, 'CampaignFund', 'campaign_id', 'select' => 'SUM(invitesCount)'),
    

    and use this relation in your criteria.