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