用户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再查询就又正常了,请教大家是什么情况? 最佳答案