Relational field displaying (not set) in gridview

I have the following tables and relationships:

Table: Sale

Fields: Lister, Seller

Table: Staff

Fields: id, initials

The db relationship is to use the Lister and Seller ID in the Sale table, but display the initials in the gridview like this:



I believe my relationships are not set up correctly as the above is showing "(not set)" in the gridview (obviously i have triple checked the database data is correct).

The relationships I do have in Sale model is:

public function getLister()


    return $this->hasOne(Staff::className(), ['id' => 'lister']);


public function getSeller()


    return $this->hasOne(Staff::className(), ['id' => 'seller']);


Can anyone recommend how to fix the relationship - or whatever else I may be doing wrong to have the wrong output.

Eg in the tables:


Lister | Seller

1 | 1


ID | Initials

1 | MJ

Whereby, in the gridview I need to show "MJ" above

I just used Gii to regen the model for Sale and its weird - it produced the following relation:

public function getLister0()


    return $this->hasOne(Staff::className(), ['id' => 'lister']);


public function getSeller0()


    return $this->hasOne(Staff::className(), ['id' => 'seller']);


Why would it generate the getLister/Seller"0" - appending that zero ?

Is the structure of my DB for what i am trying to achieve incorrect ?

It’s because your Sale model already has ‘lister’ and ‘seller’ attributes that are from the column names of ‘sale’ table.

It is also the reason why your ‘getLister()’ relation didn’t work as expected. An attribute based on a column name takes precedence over the relation with the same name.

You may want to rename your columns from ‘lister’ and ‘seller’ to ‘lister_id’ and ‘seller_id’. :)

omg thank you so much , was banging my head for ages on this - changing those column names did the job !