F
F
fayd552019-11-16 15:26:18
Yii
fayd55, 2019-11-16 15:26:18

How to filter HasOne relationship through joining table in Yii2?

Hello, I ran into a situation where in a GridView you need to display a DropDownList from a HasOne connection that works through another connection.
There are no problems with the output of the necessary data, I don’t understand how to do filtering Help me
understand using the example of three tables (abonent, nas, radacct )

public function getNas()
    {
      return $this->hasOne(Nas::className(), ['nasname' => 'nasipaddress']);
      }
      
    public function getAbonents()
    {
      return $this->hasOne(Abonent::className(), ['id' => 'abonent_id'])->via('nas');
      }    

      public function getAbonentsName()
    {
      return (isset($this->abonents))?$this->abonents->name:'не задан';
      }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question