Hi, sorry if this isn’t the right place to post this.
I’m developing a web application with Yii2 framework, and i’m facing a problem now. I want to display and search data from a many-to-many relation in a gridview, but i can’t get the right values to show. I have 3 tables: actividad, plan_actividad and circulo_icare (plan_actividad being the junction table), actividad is related to plan_actividad and circulo_icare as well. So i have defined the following relations in Actividad model:
public function getPlanActividad()
{
return $this->hasMany(PlanActividad::classname(), ['act_id' => 'act_id']);
}
and
public function getCirculo()
{
return $this->hasMany(CirculoIcare::classname(), ['cirica_id' => 'act_id'])->via('planActividad');
}
and then accesing the data in my view index.php in a gridview as follows:
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'act_id',
['attribute' => 'Codigo Evento', 'value' => 'act_numorden'],
['attribute' => 'Nombre Evento', 'value' => 'act_nombre'],
['attribute' => 'Fecha Evento', 'value' => 'act_fecha'],
['attribute' => 'Locacion', 'value' => 'locacion.loc_nombre'],
[
'attribute' => 'Circulo',
'value' => 'circulo.cirica_nombre',
],
['attribute' => 'Circulo id', 'value' => 'planActividad.cirica_id'],
// 'act_horaini',
// 'act_horafin',
// 'act_idencuesta',
// 'act_vigencia:boolean',
// 'loc_id',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
The problem is, all the values show “not defined” in the gridview like there’s no existing relations but there are. I’ve read the documentation about working with relations in Yii2, some forum and stackoverflow post as well, can get the right values when using hasOne() in a 1-to-1 relations but can’t get n-to-n relations to work with hasMany(), always get (not defined) using hasMany().
Any help would be appreciated, let me know if any more info is needed and sorry for my bad english.