I have for models say, supplier-machine, supplier, supplier-to-part and parts.
This is how these tables are related to each other.
In Supplier model the relation is defined as below to retrieve part_name of Part table keeping supplier-to-part as junction table.
public function getSupplierToParts()
{
return $this->hasMany(SupplierToPart::className(), ['supplier_id' => 'id']);
}
public function getParts()
{
return $this->hasMany(Part::className(), ['id' => 'part_id'])->viaTable('supplier_to_part', ['supplier_id' => 'id']);
}
In Detail view I use implode to display part_name
[
'attribute'=>'Nature of business',
'value' => implode(\yii\helpers\ArrayHelper::map($model->parts, 'id', 'part_name')),
],
My question is how do I display part_name in supplier-machine model instead of supplier model?? In this case I think supplier and supplier-to-part becomes like a two junction tables. How do I solve this?