Hi,
im struggling with the gridview and displaying data from other tables. See attached Image for the relationsships in the database (this is my first post, so im not allowed to add a link to an image hoster). I can display the table “user_has_product”, but instead of the ‘product_ean’ as an integer i want to display the ‘name’ from the table ‘product’.
heres my code in the view with some comments:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'user_id',
'product_ean', //shows the id
'product_ean.name', //displays : '(not set)' in view
[
'attribute' => 'Name',
'value' => function($model) {
return join(', ', yii\helpers\ArrayHelper::map($model->productEan, 'product_ean', 'name'));
},
], //displays empty cell
'stock',
'time',
'price',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
the model has a link to the table ‘product’ by:
public function getProductEan()
{
return $this->hasOne(Product::className(), ['ean' => 'product_ean']);
}
i found solutions like this ( http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/ ) but as you can see in my code, accessing data by ‘product.name’ does not work for me…
need help
thanks