issue of CGridView and dataProvider

I have two tables,

Student (id, name);

Report_receipt (id, status);

They have MANY-MANY relationship.

Third table

Student_report_receipt (student_id, report_receipt_id)

I want to show a table with three attributes: student_id, student_name, report_receipt_status.

In the model of Student:

public function relations()



	 // add relationship for tbl_report_receipt

                'reportreceipts' => array(self::MANY_MANY, 'reportreceipt',

                                'Student_report_receipt(student_id, report_receipt_id)',





public function search()


	// Warning: Please modify the following code to remove attributes that

	// should not be searched.

	$criteria=new CDbCriteria;

            // add for receipt_report





             $criteria->together = true;


	return new CActiveDataProvider(get_class($this), array(





In the admin view file (related to Student model)

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








                'header'=>'Report Receipt Status',









And the result of student/admin

is in the picture

In the result of the table, the column of Report Receipt Status is empty.

I try to modify that code as following:


                'header'=>'Report Receipt Status',





But is does not work.

Can anyone help me got the status in table Report_receipt.status?


You named the relationship "reportreceipts". This should work:


Edit: now tested with CGridView (a many_many relationship returns an array)


(CGridView seems to handle related data different than CListView, where the dot notation obviously works for many_to_many relationships.)


Songtao FENG, did you notice my update? (Immediately removed your PM after posting an answer pointing this out).


Thanks very much, Tommy.

It works.

I may relate to 3D relationship in this case.