Cgridview from the other model

Hello guys i need your help,

i want to show in my model view the personal detail and children that they have

like this




<h1>View Lksa  <?php echo $model->lksa_name; ?></h1>


<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		//'id',

		'year',

		'lksa_code',

		'lksa_name',

		'address',

		'regency.regency_name',

		array(

		    'label'=>'Provinsi',

		    'value'=>$model->regency->province->province_name,

		),

		'email',

		'leader',

		'ownershipStatus.owner',

		'contact_person',

		'handphone_number',

		'notarial_deed',

		'npwp',

		'siop',

		'bank_account',

		'name_account',

		'account_number',

		array(

		    'label'=>'Buku Rekening',

		    'type'=>'raw',

		    'value'=>CHtml::link('view', '#', array('onclick'=>'$("#bukuRekening").dialog("open"); return false;',))),

		//'picture',

	),

)); ?>


<?php

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

    'id'=>'bukuRekening',

    'options'=>array(

        'title'=>'Buku Rekening',

        'width'=>500,

        'height'=>300,

        'autoOpen'=>false,

    ),

));

    echo CHtml::image(Yii::app()->request->baseUrl . '/images/accountPicture/' . CHtml::encode($model->picture), CHtml::encode($model->picture)

,array('height'=>'100%', 'width'=>'100%'));

$this->endWidget('zii.widgets.jui.CJuiDialog');





?>

//this cgridview to show all of the children that live in model above and their status 1

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

	'id'=>'child-data-grid',

	'dataProvider'=>$model->findAnak($model->id),

	'filter'=>$model,

	'columns'=>array(

		'id',

		'child_code',

		'child_name',

		'gender_id',

		'pob',

		'dob',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



and in model i try to put




public function relations()

	{

		

		return array(

		    

		    'childData'=>array(self::HAS_MANY,'ChildData','lksa_data_id'),

		);

	}

public function findAnak($id)

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;

		 $criteria->condition = "t.id = childData.lksa_data_id and t.id = ".$id;

		//$criteria->compare('childData.id',$id,true);

		//$criteria->addCondition('regency_id=:userReg');

		//$criteria->params = array(':id'=>$id);

		$criteria->with=array('childData');

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



and i got this error


CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'childData.lksa_data_id' in 'where clause'. The SQL statement executed was: SELECT `t`.`id` AS `t0_c0`, `t`.`year` AS `t0_c1`, `t`.`lksa_code` AS `t0_c2`, `t`.`lksa_name` AS `t0_c3`, `t`.`address` AS `t0_c4`, `t`.`regency_id` AS `t0_c5`, `t`.`email` AS `t0_c6`, `t`.`leader` AS `t0_c7`, `t`.`ownership_status_id` AS `t0_c8`, `t`.`contact_person` AS `t0_c9`, `t`.`handphone_number` AS `t0_c10`, `t`.`notarial_deed` AS `t0_c11`, `t`.`npwp` AS `t0_c12`, `t`.`siop` AS `t0_c13`, `t`.`bank_account` AS `t0_c14`, `t`.`name_account` AS `t0_c15`, `t`.`account_number` AS `t0_c16`, `t`.`picture` AS `t0_c17` FROM `lksa_data` `t` WHERE (t.id = childData.lksa_data_id and t.id = 1) LIMIT 10 

can you give me solution?please

I’m not sure but it could be that the same name of the relation and your table childData could cause the problem.

Try to rename the relation.


$criteria->condition = "t.id = childData.lksa_data_id and t.id = ".$id;

change to


 $criteria->condition = "t.id = ".$id;



if use “with” it’s no need to compare id from 2 table…

cmiiw

sorry :rolleyes: i know it’s from me…

and u don’t have field lksa_data_id in table childdata…

maybe it’s lksadata_id or lksa_id…