Phpexcel Related Data

How can I export to excel my related data ?? I’m trying something like this:

$data = Pupil::model()->with((array('pupilHasUsers'=>array('select'=>'pupilFullName','joinType'=>'INNER JOIN','condition'=>'pupilHasUsers.pupil_pupilId = pupilId',))))->findAll();

and for export:

foreach($data as $record)


                    //$objPHPExcel->getActiveSheet()->setCellValue('A'. $i,$record->pupilId);

                    $objPHPExcel->getActiveSheet()->setCellValue('B'. $i,$record->firstname);


                    $objPHPExcel->getActiveSheet()->setCellValue('H'. $i,$record->classroom_classId);

                    $objPHPExcel->getActiveSheet()->setCellValue('I'. $i,$record->pupilFullName);




But I get errors Property "Pupil.pupilFullName" is not defined.

You have to prepend the relation name. Maybe like this:

    $objPHPExcel->getActiveSheet()->setCellValue('I'. $i,$record->pupilHasUsers->pupilFullName);

When I try this I get Trying to get property of non-object

i think you can not defind the public property on Pupil model so please defind this

public $pupilFullName