tp5一对一关联hasOne无效

浏览:2857 发布日期:2017/12/27 分类:求助交流
简单的一对一关联,一个用户对应一个用户资料

用户model:class User extends Model{

    public function doctor_profile(){
        return $this->hasOne('DoctorProfile');
    }
资料model:class DoctorProfile extends Model{
    protected $field = [
      'name','department_id','introduction','update_time','photo','create_time'
    ];
    public function user()
    {
        return $this->belongsTo('User');
    }
然后在控制器里查询用户资料,代码:$user = UserModel::get(['token' => $token]);
$profile = $user->doctor_profile()->find();
查询结果一看根本不是该用户对应的资料,然后打印出SQL语句一看,根本没有跟user表关联:string(38) "SELECT * FROM `doctor_profile` LIMIT 1"而且把user里的hasOne改成hasMany再查询就又正常了,请教大家是什么情况?
最佳答案
评论( 相关
后面还有条评论,点击查看>>