Showing relational data in GridView

Dear all

I’m struggling with this easy task for a long time now… I have a table fotocategorie with a foreign key foto_idfoto to another table called foto (with PK idfoto).

What I want is a GridView, where instead of the key as an int, I want the name of foto (attribute titel).

But I does not seem to work. I did the following:

In FotoCategorieSearch I added:


     * Foto linked to this category


    public $fotocategorie_foto;


    public function rules() {

        return [

            [['idFotoCategorie', 'foto_idfoto'], 'integer'],

            [['titel', 'fotocategorie_foto'], 'safe'],



No I updated the search (with a join)

$query= FotoCategorie::find()->joinWith('fotoIdfoto');

My Fotocategorie has this:


     * @return \yii\db\ActiveQuery


    public function getFotoIdfoto()


        return $this->hasOne(Foto::className(), ['idfoto' => 'foto_idfoto']);


and a filer:

andFilterWhere(['like', 'foto.titel', $this->fotocategorie_foto]);

In the view I add:



                'dataProvider' => $dataProvider,

                'filterModel' => $searchModel,

                'columns' => [

                    ['class' => 'yii\grid\SerialColumn'],




                        'attribute' => 'fotocategorie_foto',

                        'label' => 'Foto',

                        'value' => 'foto.titel',




                    ['class' => 'yii\grid\ActionColumn'],




But this does not seem to work. What am I doing wrong? Exception is: "Getting unknown property: app\models\Fotocategorie::foto"

Thanks in advance!

Check this wiki article, it should help you understand how this works -

Dear Maurizo

This is the acutal tutorial I followed. It seems this is not working. I guess the join operation is not performing, but is there any way to check this?

Kind regards

Jens Buysse