How to link a colum at id in the same table

Hi guys, I need some help just for a condition.
I have the Table “autori” in which there is “IDAutore” column and “RIDAutore” column.
Often this two columns have the same value (ex. IDAutore = 2 / RIDAutore = 2).
But sometimes is different (ex. IDAutore = 10 / RIDAutore = 2).
I want, in this last case to show the name of the “IDAutore” author.

Example: IDAutore: 3 name: Michael RIDAutore: 3.
Example: IDAutore: 10 name: Omar RIDAutore: 3.

I want to write a condition where it’s possible to return, in case of different “IDAutore” value, the value of “RIDAutore”. So, for example “Omar” must became “Michael” in index column.
I write this condition but I don’t know how to continue:

$autore1 .= ($aut1[‘RIDAutore’] != $aut1[‘IDAutore’] ? (some code here…) : ‘’ ");

Please help me!!! Thank you very much!!!

There are many ways to solve it. One of these, add a new getter in the model.

If Autore has two relation to RIDAutore reference and IDAutore reference named RIDAutoreModel and IDAutoreModel

class Autore
{
     public function getAutoreTitle()
     {
            return $this->RIDAutore != $this->IDAutore ? $this->RIDAutoreModel->name : $this->IDAutoreModel->name;
     }
}

then you can use this property inside a GridView:

'columns' : [
       'autoreTitle',
]

or from the code $autore->autoreTitle.

Sorry but this is not what I want. Maybe I was wrong.
The structure of the table “autori” is this:

IDAutore: 20
IParte: Omar
RIDAutore: 3

So, I want to show in the column the name value (IParte) that is equal to the name value (IParte) of RIDAutore == IDAutore. In this case, I don’t want to show Omar but the value of RIDAutore (3) that is Michael. Is not a general problem, is only for a few records.
Omar (RIDAUTORE = 3) became Michael (IDAutore = 3).
I hope to be clear, sorry.

You have to refer to $this->RIDAutoreModel->name in that case. Replace RIDAutoreModel with relation to Autori model.

Thank you, I hope this is the solution