关于TP5模型的关联查询请教

浏览:521 发布日期:2019/03/01 分类:求助交流
现有user表 字段id,username,password
profile表 字段id,user_id,email,sex
创建了User模型
创建了Profile模型其中定义了public function user()
{
   return $this->belongsTo('User','user_id');
}
需求:
想通过关联查询查询user.username=小明 and profile.sex=男 的用户
请问用模型怎么查询呢?

我现在是用view视图查询Db::view('profile p')->view('user u','username,password','u.id=p.user_id')->where(['u.username'=>'小明','p.sex'='男'])->select();
最佳答案
评论( 相关
后面还有条评论,点击查看>>