TP5.0中 with预载关联可以设置别名吗?

浏览:3862 发布日期:2018/06/07 分类:ThinkPHP5专区 关键字: TP5with with别名
在实际应用环境中,假设模型A有下面的关联:// 整个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方法里,设置别名呀?
最佳答案
评论( 相关
后面还有条评论,点击查看>>