質問

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?

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top