// 整个fee的信息
public function fee(){
return $this->hasOne('fee', 'wid')->field('wid', 'cost1', 'cost2', 'totalcost', 'create_by');
}
// 只取部分fee的信息
public function simpfee(){
return $this->hasOne('fee', 'wid')->field('wid', 'cost1', 'cost2');
}在调用时用with方法:// 取完整信息 得到数据 [...主体数据, 'fee'=>...fee全部数据]
public function info(){
return $this->with('fee')->select();
}
// 取简要信息 得到数据 [...主体数据, 'simpfee'=>...fee简要数据]
public function infosimp(){
return $this->with('simpfee')->select();
}但是出来的fee信息是自动绑到with方法里对应的名字上的,请问如果能实现无论是fee、还是simpfee出来的数据都绑定到fee上面。大意是:with('simpfee as fee') (当然这种写法不正确),意思是走的simpfee方法但取到的数据绑定到fee上面。
请问如何在with方法里,设置别名呀?
最佳答案