2016-06-23 17:50:07 6067次浏览 3条回答 1 悬赏 10 金钱
    public function getDoctor()
    {
        return $this->hasOne(Doctor::className(), ['id' => 'doctor_id']);
    }

比如我在model中关联了一张doctor表,但是我想给doctor表设置别名,请问要怎么设置?

最佳答案

  • bryson 发布于 2016-06-23 18:31 举报

    Try This :

     public function getDoctor()
     {
         return $this->hasOne(Doctor::className(), ['id' => 'doctor_id'])
         ->from(['alias' => Doctor::tableName()]);
     }
    
    
    1 条回复
    回复于 2016-06-23 19:05 回复

    感谢,好用

    //例如设置表别名为d时,如下:
    return $this->hasOne(Doctor::className(), ['id' => 'doctor_id'])
         ->from(['d' => Doctor::tableName()]);
    
    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
wgx214
助理

wgx214

注册时间:2014-04-22
最后登录:2020-01-14
在线时长:6小时43分
  • 粉丝2
  • 金钱130
  • 威望0
  • 积分190

热门问题