How to display count of records in grid

Hi,

I have found an example in tutorial, but I must be doing something wrong as column with totals of participants is empty. Could you help me please?

Model:

public $participantTotal;

public function rules()

{

'participants' => array(self::MANY_MANY, 'Participant', 'ParticipantServices(ServiceId, ParticipantId)'),


'participantTotal'=>array(self::STAT, 'Participant',  

‘ParticipantServices(ServiceId, ParticipantId)’),);

}

View:

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'service-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


//'filter'=&gt;&#036;model,


'columns'=&gt;array(


	'ServiceDate',


	'participantTotal',


	),

I just took a very quick look but I would guess that you shouldn’t define a public property called participantTotal when you have a relation that is named exactly like that.

The magic getter method of CActiveRecord first returns properties of the model and if it don’t find one it searches for a relation named like that. So it will always stop at your public property which is null and possibly useless. Rename that one or rename the relation and it should work

Greetings,

Haensel

P.S.: And by the way why is your relations() function “called” rules()? :) Typo or error? If so than I wonder that you can even see a GridView ;)

Thank you Haensel!

Yes, it was a typo and your tip resolved my problem.

Regards,

Jerzy