Question

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?

Was it helpful?

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.

OTHER TIPS

Several other options:

  1. Use CStatRelation

    invitesCount=>array(self::STAT,'Invites','foreign_key_field');
    
  2. The addition of a public property can work. However, the field would only be set if you altered the default find query to include this new condition. This can be done by overriding defaultScope() or creating a new scope and using it whenever invitesCount is required.

  3. Another option would be to create a database view from the required query and create a new Model from that database view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top