抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

一对一关联

hasOne

hasOne(‘关联模型名’,’外键名’,’主键名’,’join类型’);
默认的join类型为INNER
注意:关联模型名 是驼峰法

为关联模型定义需要查询的字段

V5.0.3+版本开始支持
return $this->hasOne(‘Profile’)->field(‘id,name,email’);

hasWhere方法

$user = User::hasWhere(‘profile’,[‘email’=>‘thinkphp@qq.com‘])->find();

belongsTo

belongsTo(‘关联模型名’,’外键名’,’关联表主键名’,[‘模型别名定义’],’join类型’);

正在整理中……

评论