fetch records depend on relation

hi there

i have two tables, student and exam

each student can take how many exams that want

also have a relation in student model named getExams()

how can i fetch records from student if getExams is not empty?

thanks in advanced

hi,

in my yii2 demo project i implement code as per your query.hope this exactly u want.

in state Model:


public function getCountry()

    {

        return $this->hasOne(Country::className(), ['countryId' => 'countryId']);

    } 

state index:


[

    'value' =>function($model)

    {

        $name = empty($model->country) ? 'null' : $model->country->countryName;

        return $name;

    },

],

regards,

webin