Mapping three table relationships in yii gridview

I get foreign key mapping identifiers in gridviews. How to get values ​​instead of identifiers? The code in my gridview is as follows:

$criteria->compare('education.UniversityNameid',$this->UniversityName, true); 

my gridviews inside code

 array( 
             'name' => 'UniversityName',
             'type' => 'raw',
                'value'=>'(empty($data->education->UniversityNameid))? "" : Yii::app()->params["currencySymbol"]." ".$data->education->UniversityNameid',

       ),
+4
source share
2 answers

You have to establish a relationship in your "University" model like this

public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'UniversityName' => array(self::BELONGS_TO, 'University', 'UniversityNameid'),
        );
    }

Thank you for accessing the name

$data->education->UniversityName
+1
source

Establish a relationship in your model, for example

'u' => array(self::BELONGS_TO, 'University', 'UniversityNameid'),

and deal with her like

  'attributes'=>array(

            array('name'=>'u.UniversityName',
            'label'=>'University',),


   ),
0
source

Source: https://habr.com/ru/post/1525189/


All Articles