title: Yii2 get data from many to many relation in gridview and apply filter
body: <p>i'm developing a web application with Yii2 framework, and i'm facing a problem right now. I want to display the data from a many-to-many relation in a gridview and be able to filter from those fields later on.</p>
  
  <p>I've read the official documentation <strong><a href="http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#hasMany()-detail" rel="nofollow noreferrer">here</a></strong>, some stackoverflow post <strong><a href="https://stackoverflow.com/questions/35131847/yii2-hasmany-via-vs-hasmany-viatable-vs-find-joinwith">like this</a></strong> and other resources but can't seem to get it to work. I have 3 tables: <strong>actividad</strong>, <strong>plan_actividad</strong> and <strong>circulo_icare</strong>, <strong>actividad</strong> is related to <strong>plan_actividad</strong> and <strong>circulo_icare</strong> is also related to it (<strong>plan_actividad</strong> is the junction table). So i have defined the following relations in my <strong><em>Actividad</em></strong> model:</p>
  
  <pre><code>class Actividad extends \yii\db\ActiveRecord 
  {
     .... 
  
  public function getPlanActividad()
  {
      return $this-&gt;hasMany(PlanActividad::classname(), ['act_id' =&gt; 'act_id']);
  }
  
  public function getCirculo()
  {
      return $this-&gt;hasMany(CirculoIcare::classname(), ['cirica_id' =&gt; 'act_id'])-&gt;via('planActividad');
  }
  
  ...
  }
  </code></pre>
  
  <p>The in my view <strong><em>index.php</em></strong> i'm trying to show the values in a gridview like this:</p>
  
  <pre><code>&lt;?= GridView::widget([
      'dataProvider' =&gt; $dataProvider,
      // 'filterModel' =&gt; $searchModel,
      'columns' =&gt; [
          ['class' =&gt; 'yii\grid\SerialColumn'],
  
          // 'act_id',
          ['attribute' =&gt; 'Codigo Evento', 'value' =&gt; 'act_numorden'],
          ['attribute' =&gt; 'Nombre Evento', 'value' =&gt; 'act_nombre'],
          ['attribute' =&gt; 'Fecha Evento', 'value' =&gt; 'act_fecha'],
          ['attribute' =&gt; 'Locacion', 'value' =&gt; 'locacion.loc_nombre'],
          [
          'attribute' =&gt; 'Circulo',
          'value' =&gt; 'circulo.cirica_nombre',
  
          ],
          ['attribute' =&gt; 'Circulo id',
           'value' =&gt; 'planActividad.cirica_id',
          ],
          // 'act_horaini',
          // 'act_horafin',
          // 'act_idencuesta',
          // 'act_vigencia:boolean',
          // 'loc_id',
  
          ['class' =&gt; 'yii\grid\ActionColumn'],
      ],
  ]); ?&gt;
  </code></pre>
  
  <p>The problem is, i can't get any values to show with the <strong>circulo</strong> relation, it always shows <strong>(not set)</strong>. If i change <strong>hasMany</strong> in <strong>getPlanActividad()</strong> with <strong>hasOne()</strong> then it shows some values (only 2 of 11 it should, based on the <em>cirica_id</em> that exist on <em>plan_actividad</em> table) but these are not correct anyway. I know that i can filter for those fields later on in search view but i don't really understand why the relations doesn't work as i expected.</p>
  
  <p>Any help would be greatly appreciated, let me know if more info is needed and thank you in advance.</p>