Get data from a join of two tables yii2
<p>I'm new to yii2 and trying to make a dropdown in yii2, but i can't get the data in a correct way from the tables. This are persona and docente and they are related through id_persona. The fields i need are docente.id_docente and persona.nombre and i get them by making a join:</p>

<pre><code> $personas = Persona::find()-&gt;with('docentes')-&gt;all();
</code></pre>

<p>then i map the data i need for the dropdown:</p>

<pre><code>$data = ArrayHelper::map($personas, 'docente.id_docente','nombre');
</code></pre>

<p>I get the error the following error:</p>

<pre><code>Getting unknown property: app\models\Persona::docente
</code></pre>

<p><strong>what am i doing wrong?</strong></p>

<p>When i do a var_dump($personas) i get:</p>

<pre><code>array (size=4)
   0 =&gt; 
    object(app\models\Persona)[71]
      private '_attributes' (yii\db\BaseActiveRecord) =&gt; 
        array (size=15)
          'id_persona' =&gt; int 15
          'nombre' =&gt; string 'prueba' (length=6)
          'apellido' =&gt; string 'prueba' (length=6)
          ...
   1 =&gt; 
    object(app\models\Persona)[90]
      private '_attributes' (yii\db\BaseActiveRecord) =&gt; 
        array (size=15)
          'id_persona' =&gt; int 16
          'nombre' =&gt; string 'sebastian' (length=9)
          'apellido' =&gt; string 'carreras' (length=8) 
          ...
</code></pre>

<p>The fields from table docente are not in there, i don't understand...</p>

<p>Model persona:</p>

<pre><code>/**
* @return \yii\db\ActiveQuery
*/
public function getAlumnos()
{
  return $this-&gt;hasMany(Alumno::className(), ['id_persona' =&gt;'id_persona']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getDocentes()
{
    return $this-&gt;hasMany(Docente::className(),['id_persona'=&gt;'id_persona']);
}
</code></pre>

<p>model docente</p>

<pre><code> /**
 * @return \yii\db\ActiveQuery
 */
public function getIdPersona()
{
    return $this-&gt;hasOne(Persona::className(), ['id_persona' =&gt; 'id_persona']);
}
</code></pre>