我有3个表格(order
,order_delivery
,order_types
)。每张桌子都有模特。对于order
,我创建了gridview。表格order
包含列order_number
,表order_delivery
包含order_number
和order_delivery_code
,表格order_type
delivery_types_code
和delivery_types_name
。按顺序我写函数public function getType(){
return $this->hasOne(OrderDelivery::className(), ['order_id' => 'order_id']);
}
并在索引中写'columns' => [
['class' => 'yii\grid\SerialColumn'],
'type.order_delivery_code'
。并获取gridview中订单的order_delivery_code。对于gridview中的订单,如何从order_type
获取delivery_types_name?
答案 0 :(得分:0)
创建与OrderDelivery的关系
OrderDelivery模型中的创建与OrderDeliveryType
的关系 SearchOrder中的是这样的:
$query->with(['orderDelivery','orderDelivery.orderDeliveryType'])
并在index.php中使用GridView:
'attribute'=>'orderDelivery.orderDeliverType.delivery_types_name'