Search in same model

Got a members model with the following attributes,

id,

name,

introduced_by

introduced_by attribute refers to the id and is the old member who introduced the new member.

In detailview the following gives the new members name instead of the introducer

    [


        'attribute'=>'introduced_by',


        'value' => $model->name,


    ],

How can i get the Old members name referred by introduced_by

Add a "introducedBy" relation in "Member" model, such as:




    public function getIntroducedBy()

    {

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

    } 



and then in detail view:




[

    'attribute'=>'introduced_by',

    'value' => ($model->introducedBy!=null)?$model->introducedBy->name:null,

],



Just FYI you do not need to set the value and you can use dot notation




[

 'introducedBy.name',

 //or

['attribute'=>'indroducedBy.name']

]



Fabrizio Caldarelli - didnt work. will try other option by skworden




    public function getIntroducedBy()

    {

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

    } 



and then in detail view:




[

    'attribute'=>'introduced_by',

    'value' => ($model->introducedBy!=null)?$model->introducedBy->name:null,

],



[/quote]