Cactivedataprovider With Criteria And 1:many Relationship

Hi guys,

I’m trying to get a data provider with 1 to Many relationships and display them in my CGridView.

But I’m getting: Property “Bugs.login_name” is not defined.

How can I get the relationship and display it in my CGridView?


public function search()

	{

		$criteria = $this->getCriteria();

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

		

		$dataProvider = new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

		

		return $dataProvider;

	}


public function relations()

	{

		return array(

			'assignedTo' => array(self::BELONGS_TO, 'Profiles', 'assigned_to'),

		);

	}


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

	'id'=>'bugs-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

'login_name',

'bug_id',

'bug_file_loc',

'bug_severity',

'bug_status',

'creation_ts',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); 

If U just want to display relation field :

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

    'id'=>'bugs-grid',


    'dataProvider'=>$model->search(),


    'filter'=>$model,


    'columns'=>array(


   array(


       header => 'Login name',

// if U want to perform search or filter

       name  => 'attr.Name from Bugs class'


       value => '$data->assignedTo->login_name'


   )


   'bug_id',


   'bug_file_loc',


   'bug_severity',


   'bug_status',


   'creation_ts',


            array(


                    'class'=>'CButtonColumn',


            ),


    ),

));

Also if U want to search or filter assignedTo.login_name u should adjust search in Bugs model

Thanks for the help. It worked!

How do I adjust the search in Bugs model, that it allows to search for login_name?

Has anyone an answer?